Skip to content

Commit

Permalink
get around strange gradle behavior that unzips .gzs from dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
xster committed Dec 11, 2020
1 parent 3056079 commit f5560eb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dev/devicelab/lib/framework/apk_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final String platformLineSep = Platform.isWindows ? '\r\n' : '\n';

final List<String> flutterAssets = <String>[
'assets/flutter_assets/AssetManifest.json',
'assets/flutter_assets/NOTICES.gz',
'assets/flutter_assets/NOTICES.Z',
'assets/flutter_assets/fonts/MaterialIcons-Regular.otf',
'assets/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf',
];
Expand Down
2 changes: 1 addition & 1 deletion dev/devicelab/lib/tasks/perf_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ class CompileTest {

final _UnzipListEntry libflutter = fileToMetadata['lib/armeabi-v7a/libflutter.so'];
final _UnzipListEntry libapp = fileToMetadata['lib/armeabi-v7a/libapp.so'];
final _UnzipListEntry license = fileToMetadata['assets/flutter_assets/NOTICES.gz'];
final _UnzipListEntry license = fileToMetadata['assets/flutter_assets/NOTICES.Z'];

return <String, dynamic>{
'libflutter_uncompressed_bytes': libflutter.uncompressedSize,
Expand Down
5 changes: 4 additions & 1 deletion packages/flutter/lib/src/services/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
// NOTICES for web isn't compressed since we don't have access to
// dart:io on the client side and it's already compressed between
// the server and client.
kIsWeb ? 'NOTICES' : 'NOTICES.gz',
//
// The compressed version doesn't have a common .gz extension because
// gradle for Android non-transparently manipulates .gz files.
kIsWeb ? 'NOTICES' : 'NOTICES.Z',
cache: false,
unzip: !kIsWeb,
)
Expand Down
5 changes: 4 additions & 1 deletion packages/flutter/test/services/binding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ class TestBinding extends BindingBase with SchedulerBinding, ServicesBinding {
BinaryMessenger createBinaryMessenger() {
return super.createBinaryMessenger()
..setMockMessageHandler('flutter/assets', (ByteData? message) async {
if (const StringCodec().decodeMessage(message) == 'NOTICES.gz') {
if (const StringCodec().decodeMessage(message) == 'NOTICES.Z' && !kIsWeb) {
return Uint8List.fromList(gzip.encode(utf8.encode(licenses))).buffer.asByteData();
}
if (const StringCodec().decodeMessage(message) == 'NOTICES' && kIsWeb) {
return const StringCodec().encodeMessage(licenses);
}
return null;
});
}
Expand Down
8 changes: 7 additions & 1 deletion packages/flutter_tools/lib/src/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ class ManifestAssetBundle implements AssetBundle {

static const String _kAssetManifestJson = 'AssetManifest.json';
static const String _kNoticeFile = 'NOTICES';
static const String _kNoticeZippedFile = 'NOTICES.gz';
// Comically, this can't be name with the more common .gz file extension
// because when it's part of an AAR and brought into another APK via gradle,
// gradle individually traverses all the files of the AAR and unzips .gz
// files (b/37117906). A less common .Z extension still describes how the
// file is formatted if users want to manually inspect the application
// bundle and is recognized by default file handlers on OS such as macOS.˚
static const String _kNoticeZippedFile = 'NOTICES.Z';

@override
bool wasBuiltOnce() => _lastBuildTimestamp != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ flutter:

expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/AssetManifest.json'), exists);
expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/FontManifest.json'), exists);
expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/NOTICES.gz'), exists);
expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/NOTICES.Z'), exists);
// See https://github.com/flutter/flutter/issues/35293
expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/assets/foo/bar.png'), exists);
// See https://github.com/flutter/flutter/issues/46163
Expand Down

0 comments on commit f5560eb

Please sign in to comment.