@@ -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 ) {
@@ -482,12 +478,6 @@ void AddAssembliesFromCollection (ITaskItem[] assemblies)
482478
483479 if ( UseAssemblyStore ) {
484480 storeGenerator . Add ( assemblyStoreApkName , storeAssembly ) ;
485- } else {
486- count ++ ;
487- if ( count >= ZipArchiveEx . ZipFlushFilesLimit ) {
488- apk . Flush ( ) ;
489- count = 0 ;
490- }
491481 }
492482 }
493483 }
@@ -554,7 +544,7 @@ bool AddFileToArchiveIfNewer (ZipArchiveEx apk, string file, string inArchivePat
554544 return false ;
555545 }
556546 Log . LogDebugMessage ( $ "Adding { file } as the archive file is out of date.") ;
557- apk . Archive . AddFile ( file , inArchivePath , compressionMethod : compressionMethod ) ;
547+ apk . AddFileAndFlush ( file , inArchivePath , compressionMethod : compressionMethod ) ;
558548 return true ;
559549 }
560550
@@ -578,7 +568,7 @@ void AddAssemblyConfigEntry (ZipArchiveEx apk, string assemblyPath, string confi
578568 source . CopyTo ( dest ) ;
579569 dest . WriteByte ( 0 ) ;
580570 dest . Position = 0 ;
581- apk . Archive . AddEntry ( inArchivePath , dest , compressionMethod ) ;
571+ apk . AddEntryAndFlush ( inArchivePath , dest , compressionMethod ) ;
582572 }
583573 }
584574
@@ -625,7 +615,7 @@ void AddNativeLibraryToArchive (ZipArchiveEx apk, string abi, string filesystemP
625615 return ;
626616 }
627617 Log . LogDebugMessage ( $ "Adding native library: { filesystemPath } (APK path: { archivePath } )") ;
628- apk . Archive . AddEntry ( archivePath , File . OpenRead ( filesystemPath ) , compressionMethod ) ;
618+ apk . AddEntryAndFlush ( archivePath , File . OpenRead ( filesystemPath ) , compressionMethod ) ;
629619 }
630620
631621 void AddRuntimeLibraries ( ZipArchiveEx apk , string [ ] supportedAbis )
0 commit comments