@@ -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>
0 commit comments