Skip to content

Commit e4faacd

Browse files
Read assembly from device specific APKs when AndroidUseAssemblyStore is false
1 parent 9933938 commit e4faacd

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

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

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public AndroidAssemblyDirectoryReaderV2(string apkPath, IList<string> supportedA
1515
logger?.Invoke("Adding {0} to supported architectures for Directory Reader", abi);
1616
SupportedArchitectures.Add(abi.AbiToDeviceArchitecture());
1717
}
18-
_archiveAssemblyHelper = new ArchiveAssemblyHelper(apkPath, logger);
18+
_archiveAssemblyHelper = new ArchiveAssemblyHelper(apkPath, logger, supportedAbis);
1919
}
2020

2121
public PEReader? TryReadAssembly(string name)
@@ -59,8 +59,9 @@ internal class ArchiveAssemblyHelper
5959

6060
private readonly string _archivePath;
6161
private readonly DebugLogger? _logger;
62+
private readonly IList<string> _supportedAbis;
6263

63-
public ArchiveAssemblyHelper(string archivePath, DebugLogger? logger)
64+
public ArchiveAssemblyHelper(string archivePath, DebugLogger? logger, IList<string> supportedAbis)
6465
{
6566
if (string.IsNullOrEmpty(archivePath))
6667
{
@@ -69,6 +70,7 @@ public ArchiveAssemblyHelper(string archivePath, DebugLogger? logger)
6970

7071
_archivePath = archivePath;
7172
_logger = logger;
73+
_supportedAbis = supportedAbis;
7274
}
7375

7476
public MemoryStream? ReadEntry(string path, AndroidTargetArch arch = AndroidTargetArch.None, bool uncompressIfNecessary = false)
@@ -144,21 +146,48 @@ public ArchiveAssemblyHelper(string archivePath, DebugLogger? logger)
144146
return null;
145147
}
146148

147-
using var zip = ZipFile.OpenRead(_archivePath);
148-
foreach (var assemblyPath in potentialEntries)
149+
// First we check the base.apk
150+
if (ReadEntryFromApk(_archivePath) is {} baseEntry)
149151
{
150-
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))
151161
{
152-
_logger?.Invoke("No entry found for path '{0}' in archive '{1}'", assemblyPath, _archivePath);
153-
continue;
162+
_logger?.Invoke("No split config detected at: '{0}'", splitFilePath);
163+
}
164+
else if (ReadEntryFromApk(splitFilePath) is { } splitEntry)
165+
{
166+
return splitEntry;
154167
}
155-
156-
var ret = entry.Extract();
157-
ret.Flush();
158-
return ret;
159168
}
160169

170+
// Finally admit defeat
161171
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+
}
162191
}
163192

164193
/// <summary>

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,6 @@ public static string MakeZipArchivePath(string part1, ICollection<string>? pathP
9090
public const string MANGLED_ASSEMBLY_SATELLITE_ASSEMBLY_MARKER = "lib-";
9191
public const string SATELLITE_CULTURE_END_MARKER_CHAR = "_";
9292

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-
10593
/// <summary>
10694
/// When an AAB file is deployed, the APK is split into multiple APKs so our modules can end up in a companion
10795
/// architecture specific APK like split_config.arm64_v8a.apk. This method returns the path to that split_config APK

0 commit comments

Comments
 (0)