@@ -109,6 +109,12 @@ public class BuildApk : AndroidTask
109
109
110
110
public int ZipAlignmentPages { get ; set ; } = AndroidZipAlign . DefaultZipAlignment64Bit ;
111
111
112
+ [ Required ]
113
+ public string AndroidBinUtilsDirectory { get ; set ; }
114
+
115
+ [ Required ]
116
+ public string IntermediateOutputPath { get ; set ; }
117
+
112
118
[ Required ]
113
119
public string ProjectFullPath { get ; set ; }
114
120
@@ -141,7 +147,7 @@ protected virtual void FixupArchive (ZipArchiveEx zip) { }
141
147
142
148
List < Regex > includePatterns = new List < Regex > ( ) ;
143
149
144
- void ExecuteWithAbi ( string [ ] supportedAbis , string apkInputPath , string apkOutputPath , bool debug , bool compress , IDictionary < AndroidTargetArch , Dictionary < string , CompressedAssemblyInfo > > compressedAssembliesInfo , string assemblyStoreApkName )
150
+ void ExecuteWithAbi ( DSOWrapperGenerator . Config dsoWrapperConfig , string [ ] supportedAbis , string apkInputPath , string apkOutputPath , bool debug , bool compress , IDictionary < AndroidTargetArch , Dictionary < string , CompressedAssemblyInfo > > compressedAssembliesInfo , string assemblyStoreApkName )
145
151
{
146
152
ArchiveFileList files = new ArchiveFileList ( ) ;
147
153
bool refresh = true ;
@@ -208,11 +214,11 @@ void ExecuteWithAbi (string [] supportedAbis, string apkInputPath, string apkOut
208
214
}
209
215
210
216
if ( EmbedAssemblies ) {
211
- AddAssemblies ( apk , debug , compress , compressedAssembliesInfo , assemblyStoreApkName ) ;
217
+ AddAssemblies ( dsoWrapperConfig , apk , debug , compress , compressedAssembliesInfo , assemblyStoreApkName ) ;
212
218
apk . Flush ( ) ;
213
219
}
214
220
215
- AddRuntimeConfigBlob ( apk ) ;
221
+ AddRuntimeConfigBlob ( dsoWrapperConfig , apk ) ;
216
222
AddRuntimeLibraries ( apk , supportedAbis ) ;
217
223
apk . Flush ( ) ;
218
224
AddNativeLibraries ( files , supportedAbis ) ;
@@ -354,14 +360,17 @@ public override bool RunTask ()
354
360
throw new InvalidOperationException ( $ "Assembly compression info not found for key '{ key } '. Compression will not be performed.") ;
355
361
}
356
362
357
- ExecuteWithAbi ( SupportedAbis , ApkInputPath , ApkOutputPath , debug , compress , compressedAssembliesInfo , assemblyStoreApkName : null ) ;
363
+ DSOWrapperGenerator . Config dsoWrapperConfig = DSOWrapperGenerator . GetConfig ( Log , AndroidBinUtilsDirectory , IntermediateOutputPath ) ;
364
+ ExecuteWithAbi ( dsoWrapperConfig , SupportedAbis , ApkInputPath , ApkOutputPath , debug , compress , compressedAssembliesInfo , assemblyStoreApkName : null ) ;
358
365
outputFiles . Add ( ApkOutputPath ) ;
359
366
if ( CreatePackagePerAbi && SupportedAbis . Length > 1 ) {
367
+ var abiArray = new string [ ] { String . Empty } ;
360
368
foreach ( var abi in SupportedAbis ) {
361
369
existingEntries . Clear ( ) ;
362
370
var path = Path . GetDirectoryName ( ApkOutputPath ) ;
363
371
var apk = Path . GetFileNameWithoutExtension ( ApkOutputPath ) ;
364
- ExecuteWithAbi ( new [ ] { abi } , String . Format ( "{0}-{1}" , ApkInputPath , abi ) ,
372
+ abiArray [ 0 ] = abi ;
373
+ ExecuteWithAbi ( dsoWrapperConfig , abiArray , String . Format ( "{0}-{1}" , ApkInputPath , abi ) ,
365
374
Path . Combine ( path , String . Format ( "{0}-{1}.apk" , apk , abi ) ) ,
366
375
debug , compress , compressedAssembliesInfo , assemblyStoreApkName : abi ) ;
367
376
outputFiles . Add ( Path . Combine ( path , String . Format ( "{0}-{1}.apk" , apk , abi ) ) ) ;
@@ -371,20 +380,11 @@ public override bool RunTask ()
371
380
OutputFiles = outputFiles . Select ( a => new TaskItem ( a ) ) . ToArray ( ) ;
372
381
373
382
Log . LogDebugTaskItems ( " [Output] OutputFiles :" , OutputFiles ) ;
374
- DSOWrapperGenerator . CleanUp ( this ) ;
383
+ DSOWrapperGenerator . CleanUp ( dsoWrapperConfig ) ;
375
384
376
385
return ! Log . HasLoggedErrors ;
377
386
}
378
387
379
- internal DSOWrapperGenerator . Config EnsureConfig ( )
380
- {
381
- var config = BuildEngine4 . GetRegisteredTaskObjectAssemblyLocal < DSOWrapperGenerator . Config > ( ProjectSpecificTaskObjectKey ( DSOWrapperGenerator . RegisteredConfigKey ) , RegisteredTaskObjectLifetime . Build ) ;
382
- if ( config is null ) {
383
- throw new InvalidOperationException ( "Internal error: no registered config found" ) ;
384
- }
385
- return config ;
386
- }
387
-
388
388
static Regex FileGlobToRegEx ( string fileGlob , RegexOptions options )
389
389
{
390
390
StringBuilder sb = new StringBuilder ( ) ;
@@ -403,7 +403,7 @@ static Regex FileGlobToRegEx (string fileGlob, RegexOptions options)
403
403
return new Regex ( sb . ToString ( ) , options ) ;
404
404
}
405
405
406
- void AddRuntimeConfigBlob ( ZipArchiveEx apk )
406
+ void AddRuntimeConfigBlob ( DSOWrapperGenerator . Config dsoWrapperConfig , ZipArchiveEx apk )
407
407
{
408
408
// We will place rc.bin in the `lib` directory next to the blob, to make startup slightly faster, as we will find the config file right after we encounter
409
409
// our assembly store. Not only that, but also we'll be able to skip scanning the `base.apk` archive when split configs are enabled (which they are in 99%
@@ -414,13 +414,13 @@ void AddRuntimeConfigBlob (ZipArchiveEx apk)
414
414
// Prefix it with `a` because bundletool sorts entries alphabetically, and this will place it right next to `assemblies.*.blob.so`, which is what we
415
415
// like since we can finish scanning the zip central directory earlier at startup.
416
416
string inArchivePath = MakeArchiveLibPath ( abi , "libarc.bin.so" ) ;
417
- string wrappedSourcePath = DSOWrapperGenerator . WrapIt ( MonoAndroidHelper . AbiToTargetArch ( abi ) , RuntimeConfigBinFilePath , Path . GetFileName ( inArchivePath ) , this ) ;
417
+ string wrappedSourcePath = DSOWrapperGenerator . WrapIt ( Log , dsoWrapperConfig , MonoAndroidHelper . AbiToTargetArch ( abi ) , RuntimeConfigBinFilePath , Path . GetFileName ( inArchivePath ) ) ;
418
418
AddFileToArchiveIfNewer ( apk , wrappedSourcePath , inArchivePath , compressionMethod : GetCompressionMethod ( inArchivePath ) ) ;
419
419
}
420
420
}
421
421
}
422
422
423
- void AddAssemblies ( ZipArchiveEx apk , bool debug , bool compress , IDictionary < AndroidTargetArch , Dictionary < string , CompressedAssemblyInfo > > compressedAssembliesInfo , string assemblyStoreApkName )
423
+ void AddAssemblies ( DSOWrapperGenerator . Config dsoWrapperConfig , ZipArchiveEx apk , bool debug , bool compress , IDictionary < AndroidTargetArch , Dictionary < string , CompressedAssemblyInfo > > compressedAssembliesInfo , string assemblyStoreApkName )
424
424
{
425
425
string sourcePath ;
426
426
AssemblyCompression . AssemblyData compressedAssembly = null ;
@@ -455,7 +455,7 @@ void AddAssemblies (ZipArchiveEx apk, bool debug, bool compress, IDictionary<And
455
455
foreach ( var kvp in assemblyStorePaths ) {
456
456
string abi = MonoAndroidHelper . ArchToAbi ( kvp . Key ) ;
457
457
inArchivePath = MakeArchiveLibPath ( abi , "lib" + Path . GetFileName ( kvp . Value ) ) ;
458
- string wrappedSourcePath = DSOWrapperGenerator . WrapIt ( kvp . Key , kvp . Value , Path . GetFileName ( inArchivePath ) , this ) ;
458
+ string wrappedSourcePath = DSOWrapperGenerator . WrapIt ( Log , dsoWrapperConfig , kvp . Key , kvp . Value , Path . GetFileName ( inArchivePath ) ) ;
459
459
AddFileToArchiveIfNewer ( apk , wrappedSourcePath , inArchivePath , GetCompressionMethod ( inArchivePath ) ) ;
460
460
}
461
461
@@ -474,12 +474,12 @@ void DoAddAssembliesFromArchCollection (TaskLoggingHelper log, AndroidTargetArch
474
474
475
475
// Add assembly
476
476
( string assemblyPath , string assemblyDirectory ) = GetInArchiveAssemblyPath ( assembly ) ;
477
- string wrappedSourcePath = DSOWrapperGenerator . WrapIt ( arch , sourcePath , Path . GetFileName ( assemblyPath ) , this ) ;
477
+ string wrappedSourcePath = DSOWrapperGenerator . WrapIt ( Log , dsoWrapperConfig , arch , sourcePath , Path . GetFileName ( assemblyPath ) ) ;
478
478
AddFileToArchiveIfNewer ( apk , wrappedSourcePath , assemblyPath , compressionMethod : GetCompressionMethod ( assemblyPath ) ) ;
479
479
480
480
// Try to add config if exists
481
481
var config = Path . ChangeExtension ( assembly . ItemSpec , "dll.config" ) ;
482
- AddAssemblyConfigEntry ( apk , arch , assemblyDirectory , config ) ;
482
+ AddAssemblyConfigEntry ( dsoWrapperConfig , apk , arch , assemblyDirectory , config ) ;
483
483
484
484
// Try to add symbols if Debug
485
485
if ( ! debug ) {
@@ -492,7 +492,7 @@ void DoAddAssembliesFromArchCollection (TaskLoggingHelper log, AndroidTargetArch
492
492
}
493
493
494
494
string archiveSymbolsPath = assemblyDirectory + MonoAndroidHelper . MakeDiscreteAssembliesEntryName ( Path . GetFileName ( symbols ) ) ;
495
- string wrappedSymbolsPath = DSOWrapperGenerator . WrapIt ( arch , symbols , Path . GetFileName ( archiveSymbolsPath ) , this ) ;
495
+ string wrappedSymbolsPath = DSOWrapperGenerator . WrapIt ( Log , dsoWrapperConfig , arch , symbols , Path . GetFileName ( archiveSymbolsPath ) ) ;
496
496
AddFileToArchiveIfNewer (
497
497
apk ,
498
498
wrappedSymbolsPath ,
@@ -531,7 +531,7 @@ bool AddFileToArchiveIfNewer (ZipArchiveEx apk, string file, string inArchivePat
531
531
return true ;
532
532
}
533
533
534
- void AddAssemblyConfigEntry ( ZipArchiveEx apk , AndroidTargetArch arch , string assemblyPath , string configFile )
534
+ void AddAssemblyConfigEntry ( DSOWrapperGenerator . Config dsoWrapperConfig , ZipArchiveEx apk , AndroidTargetArch arch , string assemblyPath , string configFile )
535
535
{
536
536
string inArchivePath = MonoAndroidHelper . MakeDiscreteAssembliesEntryName ( assemblyPath + Path . GetFileName ( configFile ) ) ;
537
537
existingEntries . Remove ( inArchivePath ) ;
@@ -547,7 +547,7 @@ void AddAssemblyConfigEntry (ZipArchiveEx apk, AndroidTargetArch arch, string as
547
547
}
548
548
549
549
Log . LogDebugMessage ( $ "Adding { configFile } as the archive file is out of date.") ;
550
- string wrappedConfigFile = DSOWrapperGenerator . WrapIt ( arch , configFile , Path . GetFileName ( inArchivePath ) , this ) ;
550
+ string wrappedConfigFile = DSOWrapperGenerator . WrapIt ( Log , dsoWrapperConfig , arch , configFile , Path . GetFileName ( inArchivePath ) ) ;
551
551
apk . AddFileAndFlush ( wrappedConfigFile , inArchivePath , compressionMethod ) ;
552
552
}
553
553
0 commit comments