@@ -10,6 +10,7 @@ import 'package:meta/meta.dart';
1010import '../android/android_sdk.dart' ;
1111import '../application_package.dart' ;
1212import '../artifacts.dart' ;
13+ import '../base/bsdiff.dart' ;
1314import '../base/common.dart' ;
1415import '../base/file_system.dart' ;
1516import '../base/logger.dart' ;
@@ -498,6 +499,7 @@ Future<void> _buildGradleProjectV2(
498499 throwToolExit ('Error: Could not find baseline package ${baselineApkFile .path }.' );
499500
500501 printStatus ('Found baseline package ${baselineApkFile .path }.' );
502+ printStatus ('Creating dynamic patch...' );
501503 final Archive newApk = ZipDecoder ().decodeBytes (apkFile.readAsBytesSync ());
502504 final Archive oldApk = ZipDecoder ().decodeBytes (baselineApkFile.readAsBytesSync ());
503505
@@ -519,7 +521,14 @@ Future<void> _buildGradleProjectV2(
519521 throwToolExit ("Error: Dynamic patching doesn't support changes to ${newFile .name }." );
520522
521523 final String name = fs.path.relative (newFile.name, from: 'assets/' );
522- update.addFile (ArchiveFile (name, newFile.content.length, newFile.content));
524+ if (name.contains ('_snapshot_' )) {
525+ final List <int > diff = bsdiff (oldFile.content, newFile.content);
526+ final int ratio = 100 * diff.length ~ / newFile.content.length;
527+ printStatus ('Deflated $name by ${ratio == 0 ? 99 : 100 - ratio }%' );
528+ update.addFile (ArchiveFile (name + '.bzdiff40' , diff.length, diff));
529+ } else {
530+ update.addFile (ArchiveFile (name, newFile.content.length, newFile.content));
531+ }
523532 }
524533
525534 File updateFile;
@@ -567,7 +576,8 @@ Future<void> _buildGradleProjectV2(
567576
568577 updateFile.parent.createSync (recursive: true );
569578 updateFile.writeAsBytesSync (ZipEncoder ().encode (update), flush: true );
570- printStatus ('Created dynamic patch ${updateFile .path }.' );
579+ final String patchSize = getSizeAsMB (updateFile.lengthSync ());
580+ printStatus ('Created dynamic patch ${updateFile .path } ($patchSize ).' );
571581 }
572582 } else {
573583 final File bundleFile = _findBundleFile (project, buildInfo);
0 commit comments