Skip to content

Commit daaa5ca

Browse files
jamescrosswellbruno-garciagetsentry-botgetsentry-bot
authored
Fixes symbolication for net9.0-android applications in Release config (#4221)
* Fixes symbolication for net9.0-android applications in Release configuration Resolves #4209: - #4209 (comment) * Update CHANGELOG.md * Read assembly from device specific APKs when AndroidUseAssemblyStore is false * Format code * release: 5.8.2-beta.1 * Update CHANGELOG.md --------- Co-authored-by: Bruno Garcia <bruno@brunogarcia.com> Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io> Co-authored-by: getsentry-bot <bot@sentry.io> Co-authored-by: getsentry-bot <bot@getsentry.com>
1 parent aebd6a2 commit daaa5ca

File tree

6 files changed

+86
-18
lines changed

6 files changed

+86
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Fixes
1010

11+
- Fixed symbolication for net9.0-android applications in Release config ([#4221](https://github.com/getsentry/sentry-dotnet/pull/4221))
1112
- Support Linux arm64 on Native AOT ([#3700](https://github.com/getsentry/sentry-dotnet/pull/3700))
1213
- Revert W3C traceparent support ([#4204](https://github.com/getsentry/sentry-dotnet/pull/4204))
1314

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup>
4-
<VersionPrefix>5.8.1</VersionPrefix>
4+
<VersionPrefix>5.8.2-beta.1</VersionPrefix>
55
<LangVersion>13</LangVersion>
66
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
77
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

src/Sentry.Android.AssemblyReader/V2/AndroidAssemblyDirectoryReaderV2.cs

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ public AndroidAssemblyDirectoryReaderV2(string apkPath, IList<string> supportedA
1212
Logger = logger;
1313
foreach (var abi in supportedAbis)
1414
{
15+
logger?.Invoke("Adding {0} to supported architectures for Directory Reader", abi);
1516
SupportedArchitectures.Add(abi.AbiToDeviceArchitecture());
1617
}
17-
_archiveAssemblyHelper = new ArchiveAssemblyHelper(apkPath, logger);
18+
_archiveAssemblyHelper = new ArchiveAssemblyHelper(apkPath, logger, supportedAbis);
1819
}
1920

2021
public PEReader? TryReadAssembly(string name)
@@ -25,11 +26,13 @@ public AndroidAssemblyDirectoryReaderV2(string apkPath, IList<string> supportedA
2526
var stream = File.OpenRead(name);
2627
return new PEReader(stream);
2728
}
29+
Logger?.Invoke("File {0} does not exist in the APK", name);
2830

2931
foreach (var arch in SupportedArchitectures)
3032
{
3133
if (_archiveAssemblyHelper.ReadEntry($"assemblies/{name}", arch) is not { } memStream)
3234
{
35+
Logger?.Invoke("Couldn't find entry {0} in the APK for the {1} architecture", name, arch);
3336
continue;
3437
}
3538

@@ -56,8 +59,9 @@ internal class ArchiveAssemblyHelper
5659

5760
private readonly string _archivePath;
5861
private readonly DebugLogger? _logger;
62+
private readonly IList<string> _supportedAbis;
5963

60-
public ArchiveAssemblyHelper(string archivePath, DebugLogger? logger)
64+
public ArchiveAssemblyHelper(string archivePath, DebugLogger? logger, IList<string> supportedAbis)
6165
{
6266
if (string.IsNullOrEmpty(archivePath))
6367
{
@@ -66,6 +70,7 @@ public ArchiveAssemblyHelper(string archivePath, DebugLogger? logger)
6670

6771
_archivePath = archivePath;
6872
_logger = logger;
73+
_supportedAbis = supportedAbis;
6974
}
7075

7176
public MemoryStream? ReadEntry(string path, AndroidTargetArch arch = AndroidTargetArch.None, bool uncompressIfNecessary = false)
@@ -137,23 +142,52 @@ public ArchiveAssemblyHelper(string archivePath, DebugLogger? logger)
137142
var potentialEntries = TransformArchiveAssemblyPath(path, arch);
138143
if (potentialEntries == null || potentialEntries.Count == 0)
139144
{
145+
_logger?.Invoke("No potential entries for path '{0}' with arch '{1}'", path, arch);
140146
return null;
141147
}
142148

143-
using var zip = ZipFile.OpenRead(_archivePath);
144-
foreach (var assemblyPath in potentialEntries)
149+
// First we check the base.apk
150+
if (ReadEntryFromApk(_archivePath) is { } baseEntry)
145151
{
146-
if (zip.GetEntry(assemblyPath) is not { } entry)
152+
_logger?.Invoke("Found entry '{0}' in base archive '{1}'", path, _archivePath);
153+
return baseEntry;
154+
}
155+
156+
// Otherwise check in the device specific APKs
157+
foreach (var supportedAbi in _supportedAbis)
158+
{
159+
var splitFilePath = _archivePath.GetArchivePathForAbi(supportedAbi, _logger);
160+
if (!File.Exists(splitFilePath))
147161
{
148-
continue;
162+
_logger?.Invoke("No split config detected at: '{0}'", splitFilePath);
163+
}
164+
else if (ReadEntryFromApk(splitFilePath) is { } splitEntry)
165+
{
166+
return splitEntry;
149167
}
150-
151-
var ret = entry.Extract();
152-
ret.Flush();
153-
return ret;
154168
}
155169

170+
// Finally admit defeat
156171
return null;
172+
173+
MemoryStream? ReadEntryFromApk(string archivePath)
174+
{
175+
using var zip = ZipFile.OpenRead(archivePath);
176+
foreach (var assemblyPath in potentialEntries)
177+
{
178+
if (zip.GetEntry(assemblyPath) is not { } entry)
179+
{
180+
_logger?.Invoke("No entry found for path '{0}' in archive '{1}'", assemblyPath, archivePath);
181+
continue;
182+
}
183+
184+
var ret = entry.Extract();
185+
ret.Flush();
186+
return ret;
187+
}
188+
189+
return null;
190+
}
157191
}
158192

159193
/// <summary>

src/Sentry.Android.AssemblyReader/V2/AndroidAssemblyStoreReaderV2.cs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,35 @@ private AndroidAssemblyStoreReaderV2(IList<AssemblyStoreExplorer> explorers, Deb
1313

1414
public static bool TryReadStore(string inputFile, IList<string> supportedAbis, DebugLogger? logger, [NotNullWhen(true)] out AndroidAssemblyStoreReaderV2? reader)
1515
{
16+
List<AssemblyStoreExplorer> supportedExplorers = [];
17+
18+
// First we check the base.apk for an assembly store
1619
var (explorers, errorMessage) = AssemblyStoreExplorer.Open(inputFile, logger);
17-
if (errorMessage != null)
20+
if (explorers is null)
1821
{
19-
logger?.Invoke(errorMessage);
20-
reader = null;
21-
return false;
22-
}
22+
logger?.Invoke("Unable to read store information for {0}: {1}", inputFile, errorMessage);
2323

24-
List<AssemblyStoreExplorer> supportedExplorers = [];
25-
if (explorers is not null)
24+
// Check for assembly stores in any device specific APKs
25+
foreach (var supportedAbi in supportedAbis)
26+
{
27+
var splitFilePath = inputFile.GetArchivePathForAbi(supportedAbi, logger);
28+
if (!File.Exists(splitFilePath))
29+
{
30+
logger?.Invoke("No split config detected at: '{0}'", splitFilePath);
31+
continue;
32+
}
33+
(explorers, errorMessage) = AssemblyStoreExplorer.Open(splitFilePath, logger);
34+
if (explorers is not null)
35+
{
36+
supportedExplorers.AddRange(explorers); // If the error is null then this is not null
37+
}
38+
else
39+
{
40+
logger?.Invoke("Unable to read store information for {0}: {1}", splitFilePath, errorMessage);
41+
}
42+
}
43+
}
44+
else
2645
{
2746
foreach (var explorer in explorers)
2847
{

src/Sentry.Android.AssemblyReader/V2/MonoAndroidHelper.Basic.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,17 @@ public static string MakeZipArchivePath(string part1, ICollection<string>? pathP
8989
public const string MANGLED_ASSEMBLY_REGULAR_ASSEMBLY_MARKER = "lib_";
9090
public const string MANGLED_ASSEMBLY_SATELLITE_ASSEMBLY_MARKER = "lib-";
9191
public const string SATELLITE_CULTURE_END_MARKER_CHAR = "_";
92+
93+
/// <summary>
94+
/// When an AAB file is deployed, the APK is split into multiple APKs so our modules can end up in a companion
95+
/// architecture specific APK like split_config.arm64_v8a.apk. This method returns the path to that split_config APK
96+
/// if it exists... otherwise we just return the original archive path.
97+
/// </summary>
98+
internal static string GetArchivePathForAbi(this string archivePath, string abi, DebugLogger? logger)
99+
{
100+
var basePath = Path.GetDirectoryName(archivePath) ?? string.Empty;
101+
var abiPart = abi.Replace("-", "_");
102+
var splitFilePath = Path.Combine(basePath, $"split_config.{abiPart}.apk");
103+
return splitFilePath;
104+
}
92105
}

src/Sentry/Internal/DebugStackTrace.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ private IEnumerable<SentryStackFrame> CreateFrames(StackTrace stackTrace, bool i
249249
return null;
250250
}
251251

252+
_options.LogDebug("Attempting to get debug image for native AOT Frame");
252253
var imageAddress = stackFrame.GetNativeImageBase();
253254
var frame = ParseNativeAOTToString(stackFrame.ToString());
254255
frame.ImageAddress = imageAddress;

0 commit comments

Comments
 (0)