Skip to content

Commit 2c13d2f

Browse files
Fixes symbolication for net9.0-android applications in Release configuration
Resolves #4209: - #4209 (comment)
1 parent b97aec8 commit 2c13d2f

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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
}
1718
_archiveAssemblyHelper = new ArchiveAssemblyHelper(apkPath, logger);
@@ -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

@@ -137,6 +140,7 @@ public ArchiveAssemblyHelper(string archivePath, DebugLogger? logger)
137140
var potentialEntries = TransformArchiveAssemblyPath(path, arch);
138141
if (potentialEntries == null || potentialEntries.Count == 0)
139142
{
143+
_logger?.Invoke("No potential entries for path '{0}' with arch '{1}'", path, arch);
140144
return null;
141145
}
142146

@@ -145,6 +149,7 @@ public ArchiveAssemblyHelper(string archivePath, DebugLogger? logger)
145149
{
146150
if (zip.GetEntry(assemblyPath) is not { } entry)
147151
{
152+
_logger?.Invoke("No entry found for path '{0}' in archive '{1}'", assemblyPath, _archivePath);
148153
continue;
149154
}
150155

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,29 @@ 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 GetArchivePathForArchitecture(this string archivePath, AndroidTargetArch arch, DebugLogger? logger)
99+
{
100+
return ArchToAbiMap.TryGetValue(arch, out var abi)
101+
? GetArchivePathForAbi(archivePath, abi, logger)
102+
: archivePath;
103+
}
104+
105+
/// <summary>
106+
/// When an AAB file is deployed, the APK is split into multiple APKs so our modules can end up in a companion
107+
/// architecture specific APK like split_config.arm64_v8a.apk. This method returns the path to that split_config APK
108+
/// if it exists... otherwise we just return the original archive path.
109+
/// </summary>
110+
internal static string GetArchivePathForAbi(this string archivePath, string abi, DebugLogger? logger)
111+
{
112+
var basePath = Path.GetDirectoryName(archivePath) ?? string.Empty;
113+
var abiPart = abi.Replace("-", "_");
114+
var splitFilePath = Path.Combine(basePath, $"split_config.{abiPart}.apk");
115+
return splitFilePath;
116+
}
92117
}

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)