@@ -95,6 +95,10 @@ public class BuildApk : AndroidTask
9595
9696 public bool UseAssemblyStore { get ; set ; }
9797
98+ public string ZipFlushFilesLimit { get ; set ; }
99+
100+ public string ZipFlushSizeLimit { get ; set ; }
101+
98102 [ Required ]
99103 public string ProjectFullPath { get ; set ; }
100104
@@ -206,7 +210,6 @@ void ExecuteWithAbi (string [] supportedAbis, string apkInputPath, string apkOut
206210 AddFileToArchiveIfNewer ( apk , RuntimeConfigBinFilePath , $ "{ AssembliesPath } rc.bin", compressionMethod : UncompressedMethod ) ;
207211 }
208212
209- int count = 0 ;
210213 foreach ( var file in files ) {
211214 var item = Path . Combine ( file . archivePath . Replace ( Path . DirectorySeparatorChar , '/' ) ) ;
212215 existingEntries . Remove ( item ) ;
@@ -216,12 +219,7 @@ void ExecuteWithAbi (string [] supportedAbis, string apkInputPath, string apkOut
216219 continue ;
217220 }
218221 Log . LogDebugMessage ( "\t Adding {0}" , file . filePath ) ;
219- apk . Archive . AddFile ( file . filePath , item , compressionMethod : compressionMethod ) ;
220- count ++ ;
221- if ( count >= ZipArchiveEx . ZipFlushFilesLimit ) {
222- apk . Flush ( ) ;
223- count = 0 ;
224- }
222+ apk . AddFileAndFlush ( file . filePath , item , compressionMethod : compressionMethod ) ;
225223 }
226224
227225 var jarFiles = ( JavaSourceFiles != null ) ? JavaSourceFiles . Where ( f => f . ItemSpec . EndsWith ( ".jar" , StringComparison . OrdinalIgnoreCase ) ) : null ;
@@ -236,7 +234,6 @@ void ExecuteWithAbi (string [] supportedAbis, string apkInputPath, string apkOut
236234 var jarFilePaths = libraryProjectJars . Concat ( jarFiles != null ? jarFiles . Select ( j => j . ItemSpec ) : Enumerable . Empty < string > ( ) ) ;
237235 jarFilePaths = MonoAndroidHelper . DistinctFilesByContent ( jarFilePaths ) ;
238236
239- count = 0 ;
240237 foreach ( var jarFile in jarFilePaths ) {
241238 using ( var stream = File . OpenRead ( jarFile ) )
242239 using ( var jar = ZipArchive . Open ( stream ) ) {
@@ -278,14 +275,9 @@ void ExecuteWithAbi (string [] supportedAbis, string apkInputPath, string apkOut
278275 data = d . ToArray ( ) ;
279276 }
280277 Log . LogDebugMessage ( $ "Adding { path } from { jarFile } as the archive file is out of date.") ;
281- apk . Archive . AddEntry ( data , path ) ;
278+ apk . AddEntryAndFlush ( data , path ) ;
282279 }
283280 }
284- count ++ ;
285- if ( count >= ZipArchiveEx . ZipFlushFilesLimit ) {
286- apk . Flush ( ) ;
287- count = 0 ;
288- }
289281 }
290282 // Clean up Removed files.
291283 foreach ( var entry in existingEntries ) {
@@ -302,6 +294,12 @@ void ExecuteWithAbi (string [] supportedAbis, string apkInputPath, string apkOut
302294
303295 public override bool RunTask ( )
304296 {
297+ if ( int . TryParse ( ZipFlushFilesLimit , out int flushFilesLimit ) ) {
298+ ZipArchiveEx . ZipFlushFilesLimit = flushFilesLimit ;
299+ }
300+ if ( int . TryParse ( ZipFlushSizeLimit , out int flushSizeLimit ) ) {
301+ ZipArchiveEx . ZipFlushSizeLimit = flushSizeLimit ;
302+ }
305303 Aot . TryGetSequencePointsMode ( AndroidSequencePointsMode , out sequencePointsMode ) ;
306304
307305 var outputFiles = new List < string > ( ) ;
@@ -377,7 +375,6 @@ void AddAssemblies (ZipArchiveEx apk, bool debug, bool compress, IDictionary<str
377375 storeGenerator = null ;
378376 }
379377
380- int count = 0 ;
381378 AssemblyStoreAssemblyInfo storeAssembly = null ;
382379
383380 //
@@ -398,7 +395,6 @@ void AddAssemblies (ZipArchiveEx apk, bool debug, bool compress, IDictionary<str
398395 AddAssembliesFromCollection ( ResolvedUserAssemblies ) ;
399396
400397 // Add framework assemblies
401- count = 0 ;
402398 AddAssembliesFromCollection ( ResolvedFrameworkAssemblies ) ;
403399
404400 if ( ! UseAssemblyStore ) {
@@ -488,12 +484,6 @@ void AddAssembliesFromCollection (ITaskItem[] assemblies)
488484
489485 if ( UseAssemblyStore ) {
490486 storeGenerator . Add ( assemblyStoreApkName , storeAssembly ) ;
491- } else {
492- count ++ ;
493- if ( count >= ZipArchiveEx . ZipFlushFilesLimit ) {
494- apk . Flush ( ) ;
495- count = 0 ;
496- }
497487 }
498488 }
499489 }
@@ -560,7 +550,7 @@ bool AddFileToArchiveIfNewer (ZipArchiveEx apk, string file, string inArchivePat
560550 return false ;
561551 }
562552 Log . LogDebugMessage ( $ "Adding { file } as the archive file is out of date.") ;
563- apk . Archive . AddFile ( file , inArchivePath , compressionMethod : compressionMethod ) ;
553+ apk . AddFileAndFlush ( file , inArchivePath , compressionMethod : compressionMethod ) ;
564554 return true ;
565555 }
566556
@@ -584,7 +574,7 @@ void AddAssemblyConfigEntry (ZipArchiveEx apk, string assemblyPath, string confi
584574 source . CopyTo ( dest ) ;
585575 dest . WriteByte ( 0 ) ;
586576 dest . Position = 0 ;
587- apk . Archive . AddEntry ( inArchivePath , dest , compressionMethod ) ;
577+ apk . AddEntryAndFlush ( inArchivePath , dest , compressionMethod ) ;
588578 }
589579 }
590580
@@ -631,7 +621,7 @@ void AddNativeLibraryToArchive (ZipArchiveEx apk, string abi, string filesystemP
631621 return ;
632622 }
633623 Log . LogDebugMessage ( $ "Adding native library: { filesystemPath } (APK path: { archivePath } )") ;
634- apk . Archive . AddEntry ( archivePath , File . OpenRead ( filesystemPath ) , compressionMethod ) ;
624+ apk . AddEntryAndFlush ( archivePath , File . OpenRead ( filesystemPath ) , compressionMethod ) ;
635625 }
636626
637627 void AddRuntimeLibraries ( ZipArchiveEx apk , string [ ] supportedAbis )
0 commit comments