88using System . Reflection . PortableExecutable ;
99using System . Text ;
1010using Microsoft . Build . Framework ;
11+ using Microsoft . Build . Utilities ;
1112
1213using Java . Interop . Tools . TypeNameMappings ;
1314using Xamarin . Android . Tools ;
@@ -237,6 +238,10 @@ public override bool RunTask ()
237238 }
238239
239240 var uniqueNativeLibraries = new List < ITaskItem > ( ) ;
241+
242+ // Number of DSOs that will be packaged, it may be different to the number of items in the above
243+ // `uniqueNativeLibraries` list.
244+ uint packagedNativeLibrariesCount = 0 ;
240245 var seenNativeLibraryNames = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
241246 if ( NativeLibraries != null ) {
242247 foreach ( ITaskItem item in NativeLibraries ) {
@@ -246,9 +251,19 @@ public override bool RunTask ()
246251 continue ;
247252 }
248253
254+ if ( ! ELFHelper . IsEmptyAOTLibrary ( Log , item . ItemSpec ) ) {
255+ packagedNativeLibrariesCount ++ ;
256+ }
257+
249258 seenNativeLibraryNames . Add ( name ) ;
250259 uniqueNativeLibraries . Add ( item ) ;
251260 }
261+
262+ // libxamarin-app.so is not in NativeLibraries, but we must count it
263+ if ( ! seenNativeLibraryNames . Contains ( "libxamarin-app.so" ) ) {
264+ uniqueNativeLibraries . Add ( new TaskItem ( "libxamarin-app.so" ) ) ;
265+ packagedNativeLibrariesCount ++ ;
266+ }
252267 }
253268
254269 var jniRemappingNativeCodeInfo = BuildEngine4 . GetRegisteredTaskObjectAssemblyLocal < GenerateJniRemappingNativeCode . JniRemappingNativeCodeInfo > ( ProjectSpecificTaskObjectKey ( GenerateJniRemappingNativeCode . JniRemappingNativeCodeInfoKey ) , RegisteredTaskObjectLifetime . Build ) ;
@@ -264,6 +279,7 @@ public override bool RunTask ()
264279 NumberOfAssembliesInApk = assemblyCount ,
265280 BundledAssemblyNameWidth = assemblyNameWidth ,
266281 NativeLibraries = uniqueNativeLibraries ,
282+ PackagedNativeLibrariesCount = packagedNativeLibrariesCount ,
267283 AndroidRuntimeJNIEnvToken = android_runtime_jnienv_class_token ,
268284 JNIEnvInitializeToken = jnienv_initialize_method_token ,
269285 JNIEnvRegisterJniNativesToken = jnienv_registerjninatives_method_token ,
@@ -301,6 +317,7 @@ public override bool RunTask ()
301317 BundledAssemblyNameWidth = assemblyNameWidth ,
302318 MonoComponents = ( MonoComponent ) monoComponents ,
303319 NativeLibraries = uniqueNativeLibraries ,
320+ PackagedNativeLibrariesCount = packagedNativeLibrariesCount ,
304321 HaveAssemblyStore = UseAssemblyStore ,
305322 AndroidRuntimeJNIEnvToken = android_runtime_jnienv_class_token ,
306323 JNIEnvInitializeToken = jnienv_initialize_method_token ,
0 commit comments