Unverified Commit 40c5cc97 authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

Find the app bundle when the flavor contains underscores (#37457)

parent 80ee3dd0
...@@ -17,17 +17,14 @@ Future<void> main() async { ...@@ -17,17 +17,14 @@ Future<void> main() async {
await project.runGradleTask('bundleRelease'); await project.runGradleTask('bundleRelease');
final String releaseBundle = path.join( final String releaseBundle = path.join(
project.rootPath, project.rootPath,
'build', 'build',
'app', 'app',
'outputs', 'outputs',
'bundle', 'bundle',
'release', 'release',
'app.aab', 'app.aab',
); );
final Iterable<String> bundleFiles = await getFilesInAppBundle(releaseBundle);
checkItContains<String>(<String>[ checkItContains<String>(<String>[
'base/manifest/AndroidManifest.xml', 'base/manifest/AndroidManifest.xml',
'base/dex/classes.dex', 'base/dex/classes.dex',
...@@ -35,28 +32,66 @@ Future<void> main() async { ...@@ -35,28 +32,66 @@ Future<void> main() async {
'base/lib/arm64-v8a/libflutter.so', 'base/lib/arm64-v8a/libflutter.so',
'base/lib/armeabi-v7a/libapp.so', 'base/lib/armeabi-v7a/libapp.so',
'base/lib/armeabi-v7a/libflutter.so', 'base/lib/armeabi-v7a/libflutter.so',
], bundleFiles); ], await getFilesInAppBundle(releaseBundle));
}); });
await runProjectTest((FlutterProject project) async { await runProjectTest((FlutterProject project) async {
section('App bundle content using flavors without explicit target platform'); section('App bundle content using flavors without explicit target platform');
// Add a few flavors. // Add a few flavors.
await project.addProductFlavors(<String> ['production', 'staging', 'development']); await project.addProductFlavors(<String> [
'production',
'staging',
'development',
'flavor_underscore', // https://github.com/flutter/flutter/issues/36067
]);
// Build the production flavor in release mode. // Build the production flavor in release mode.
await project.runGradleTask('bundleProductionRelease'); await project.runGradleTask('bundleProductionRelease');
final String bundlePath = path.join( final String bundleFromGradlePath = path.join(
project.rootPath, project.rootPath,
'build',
'app',
'outputs',
'bundle',
'productionRelease',
'app.aab',
);
checkItContains<String>(<String>[
'base/manifest/AndroidManifest.xml',
'base/dex/classes.dex',
'base/lib/arm64-v8a/libapp.so',
'base/lib/arm64-v8a/libflutter.so',
'base/lib/armeabi-v7a/libapp.so',
'base/lib/armeabi-v7a/libflutter.so',
], await getFilesInAppBundle(bundleFromGradlePath));
section('Build app bundle using the flutter tool - flavor: flavor_underscore');
int exitCode;
await inDirectory(project.rootPath, () async {
exitCode = await flutter(
'build', 'build',
'app', options: <String>[
'outputs', 'appbundle',
'bundle', '--flavor=flavor_underscore',
'productionRelease', '--verbose',
'app.aab', ],
); );
});
final Iterable<String> bundleFiles = await getFilesInAppBundle(bundlePath); if (exitCode != 0) {
throw TaskResult.failure('flutter build appbundle command exited with code: $exitCode');
}
final String flavorUnderscoreBundlePath = path.join(
project.rootPath,
'build',
'app',
'outputs',
'bundle',
'flavor_underscoreRelease',
'app.aab',
);
checkItContains<String>(<String>[ checkItContains<String>(<String>[
'base/manifest/AndroidManifest.xml', 'base/manifest/AndroidManifest.xml',
'base/dex/classes.dex', 'base/dex/classes.dex',
...@@ -64,7 +99,42 @@ Future<void> main() async { ...@@ -64,7 +99,42 @@ Future<void> main() async {
'base/lib/arm64-v8a/libflutter.so', 'base/lib/arm64-v8a/libflutter.so',
'base/lib/armeabi-v7a/libapp.so', 'base/lib/armeabi-v7a/libapp.so',
'base/lib/armeabi-v7a/libflutter.so', 'base/lib/armeabi-v7a/libflutter.so',
], bundleFiles); ], await getFilesInAppBundle(flavorUnderscoreBundlePath));
section('Build app bundle using the flutter tool - flavor: production');
await inDirectory(project.rootPath, () async {
exitCode = await flutter(
'build',
options: <String>[
'appbundle',
'--flavor=production',
'--verbose',
],
);
});
if (exitCode != 0) {
throw TaskResult.failure('flutter build appbundle command exited with code: $exitCode');
}
final String productionBundlePath = path.join(
project.rootPath,
'build',
'app',
'outputs',
'bundle',
'productionRelease',
'app.aab',
);
checkItContains<String>(<String>[
'base/manifest/AndroidManifest.xml',
'base/dex/classes.dex',
'base/lib/arm64-v8a/libapp.so',
'base/lib/arm64-v8a/libflutter.so',
'base/lib/armeabi-v7a/libapp.so',
'base/lib/armeabi-v7a/libflutter.so',
], await getFilesInAppBundle(productionBundlePath));
}); });
await runProjectTest((FlutterProject project) async { await runProjectTest((FlutterProject project) async {
...@@ -73,14 +143,14 @@ Future<void> main() async { ...@@ -73,14 +143,14 @@ Future<void> main() async {
options: <String>['-Ptarget-platform=android-arm']); options: <String>['-Ptarget-platform=android-arm']);
final String releaseBundle = path.join( final String releaseBundle = path.join(
project.rootPath, project.rootPath,
'build', 'build',
'app', 'app',
'outputs', 'outputs',
'bundle', 'bundle',
'release', 'release',
'app.aab', 'app.aab',
); );
final Iterable<String> bundleFiles = await getFilesInAppBundle(releaseBundle); final Iterable<String> bundleFiles = await getFilesInAppBundle(releaseBundle);
......
...@@ -775,7 +775,7 @@ Future<void> _buildGradleProjectV2( ...@@ -775,7 +775,7 @@ Future<void> _buildGradleProjectV2(
color: TerminalColor.green); color: TerminalColor.green);
} }
} else { } else {
final File bundleFile = _findBundleFile(project, buildInfo); final File bundleFile = findBundleFile(project, buildInfo);
if (bundleFile == null) if (bundleFile == null)
throwToolExit('Gradle build failed to produce an Android bundle package.'); throwToolExit('Gradle build failed to produce an Android bundle package.');
...@@ -820,24 +820,30 @@ Iterable<File> findApkFiles(GradleProject project, AndroidBuildInfo androidBuild ...@@ -820,24 +820,30 @@ Iterable<File> findApkFiles(GradleProject project, AndroidBuildInfo androidBuild
}); });
} }
File _findBundleFile(GradleProject project, BuildInfo buildInfo) { @visibleForTesting
File findBundleFile(GradleProject project, BuildInfo buildInfo) {
final String bundleFileName = project.bundleFileFor(buildInfo); final String bundleFileName = project.bundleFileFor(buildInfo);
if (bundleFileName == null) {
if (bundleFileName == null)
return null; return null;
final String modeName = camelCase(buildInfo.modeName); }
File bundleFile = project.bundleDirectory.childDirectory(modeName).childFile(bundleFileName); File bundleFile = project.bundleDirectory
if (bundleFile.existsSync()) .childDirectory(camelCase(buildInfo.modeName))
.childFile(bundleFileName);
if (bundleFile.existsSync()) {
return bundleFile;
}
if (buildInfo.flavor == null) {
return null;
}
// Android Studio Gradle plugin v3 adds the flavor to the path. For the bundle the
// folder name is the flavor plus the mode name. On Windows, filenames aren't case sensitive.
// For example: foo_barRelease where `foo_bar` is the flavor and `Release` the mode name.
final String childDirName = '${buildInfo.flavor}${camelCase('_' + buildInfo.modeName)}';
bundleFile = project.bundleDirectory
.childDirectory(childDirName)
.childFile(bundleFileName);
if (bundleFile.existsSync()) {
return bundleFile; return bundleFile;
if (buildInfo.flavor != null) {
// Android Studio Gradle plugin v3 adds the flavor to the path. For the bundle the folder name is the flavor plus the mode name.
// On linux, filenames are case sensitive.
bundleFile = project.bundleDirectory
.childDirectory(camelCase('${buildInfo.flavor}_$modeName'))
.childFile(bundleFileName);
if (bundleFile.existsSync())
return bundleFile;
} }
return null; return null;
} }
......
...@@ -117,6 +117,150 @@ void main() { ...@@ -117,6 +117,150 @@ void main() {
expect(ndkMessageFilter.hasMatch(m), isTrue); expect(ndkMessageFilter.hasMatch(m), isTrue);
} }
}); });
testUsingContext('Finds app bundle when flavor contains underscores in release mode', () {
final GradleProject gradleProject = MockGradleProject();
when(gradleProject.bundleDirectory).thenReturn(fs.currentDirectory);
when(gradleProject.bundleFileFor(any)).thenReturn('app.aab');
final Directory aabDirectory = gradleProject.bundleDirectory.childDirectory('foo_barRelease');
fs.directory(aabDirectory).createSync(recursive: true);
fs.file(fs.path.join(aabDirectory.path, 'app.aab')).writeAsStringSync('irrelevant');
final File bundle = findBundleFile(gradleProject, const BuildInfo(BuildMode.release, 'foo_bar'));
expect(bundle, isNotNull);
expect(bundle.path, '/foo_barRelease/app.aab');
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
});
testUsingContext('Finds app bundle when flavor doesn\'t contain underscores in release mode', () {
final GradleProject gradleProject = MockGradleProject();
when(gradleProject.bundleDirectory).thenReturn(fs.currentDirectory);
when(gradleProject.bundleFileFor(any)).thenReturn('app.aab');
final Directory aabDirectory = gradleProject.bundleDirectory.childDirectory('fooRelease');
fs.directory(aabDirectory).createSync(recursive: true);
fs.file(fs.path.join(aabDirectory.path, 'app.aab')).writeAsStringSync('irrelevant');
final File bundle = findBundleFile(gradleProject, const BuildInfo(BuildMode.release, 'foo'));
expect(bundle, isNotNull);
expect(bundle.path, '/fooRelease/app.aab');
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
});
testUsingContext('Finds app bundle when no flavor is used in release mode', () {
final GradleProject gradleProject = MockGradleProject();
when(gradleProject.bundleDirectory).thenReturn(fs.currentDirectory);
when(gradleProject.bundleFileFor(any)).thenReturn('app.aab');
final Directory aabDirectory = gradleProject.bundleDirectory.childDirectory('release');
fs.directory(aabDirectory).createSync(recursive: true);
fs.file(fs.path.join(aabDirectory.path, 'app.aab')).writeAsStringSync('irrelevant');
final File bundle = findBundleFile(gradleProject, const BuildInfo(BuildMode.release, null));
expect(bundle, isNotNull);
expect(bundle.path, '/release/app.aab');
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
});
testUsingContext('Finds app bundle when flavor contains underscores in debug mode', () {
final GradleProject gradleProject = MockGradleProject();
when(gradleProject.bundleDirectory).thenReturn(fs.currentDirectory);
when(gradleProject.bundleFileFor(any)).thenReturn('app.aab');
final Directory aabDirectory = gradleProject.bundleDirectory.childDirectory('foo_barDebug');
fs.directory(aabDirectory).createSync(recursive: true);
fs.file(fs.path.join(aabDirectory.path, 'app.aab')).writeAsStringSync('irrelevant');
final File bundle = findBundleFile(gradleProject, const BuildInfo(BuildMode.debug, 'foo_bar'));
expect(bundle, isNotNull);
expect(bundle.path, '/foo_barDebug/app.aab');
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
});
testUsingContext('Finds app bundle when flavor doesn\'t contain underscores in debug mode', () {
final GradleProject gradleProject = MockGradleProject();
when(gradleProject.bundleDirectory).thenReturn(fs.currentDirectory);
when(gradleProject.bundleFileFor(any)).thenReturn('app.aab');
final Directory aabDirectory = gradleProject.bundleDirectory.childDirectory('fooDebug');
fs.directory(aabDirectory).createSync(recursive: true);
fs.file(fs.path.join(aabDirectory.path, 'app.aab')).writeAsStringSync('irrelevant');
final File bundle = findBundleFile(gradleProject, const BuildInfo(BuildMode.debug, 'foo'));
expect(bundle, isNotNull);
expect(bundle.path, '/fooDebug/app.aab');
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
});
testUsingContext('Finds app bundle when no flavor is used in debug mode', () {
final GradleProject gradleProject = MockGradleProject();
when(gradleProject.bundleDirectory).thenReturn(fs.currentDirectory);
when(gradleProject.bundleFileFor(any)).thenReturn('app.aab');
final Directory aabDirectory = gradleProject.bundleDirectory.childDirectory('debug');
fs.directory(aabDirectory).createSync(recursive: true);
fs.file(fs.path.join(aabDirectory.path, 'app.aab')).writeAsStringSync('irrelevant');
final File bundle = findBundleFile(gradleProject, const BuildInfo(BuildMode.debug, null));
expect(bundle, isNotNull);
expect(bundle.path, '/debug/app.aab');
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
});
testUsingContext('Finds app bundle when flavor contains underscores in profile mode', () {
final GradleProject gradleProject = MockGradleProject();
when(gradleProject.bundleDirectory).thenReturn(fs.currentDirectory);
when(gradleProject.bundleFileFor(any)).thenReturn('app.aab');
final Directory aabDirectory = gradleProject.bundleDirectory.childDirectory('foo_barProfile');
fs.directory(aabDirectory).createSync(recursive: true);
fs.file(fs.path.join(aabDirectory.path, 'app.aab')).writeAsStringSync('irrelevant');
final File bundle = findBundleFile(gradleProject, const BuildInfo(BuildMode.profile, 'foo_bar'));
expect(bundle, isNotNull);
expect(bundle.path, '/foo_barProfile/app.aab');
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
});
testUsingContext('Finds app bundle when flavor doesn\'t contain underscores in profile mode', () {
final GradleProject gradleProject = MockGradleProject();
when(gradleProject.bundleDirectory).thenReturn(fs.currentDirectory);
when(gradleProject.bundleFileFor(any)).thenReturn('app.aab');
final Directory aabDirectory = gradleProject.bundleDirectory.childDirectory('fooProfile');
fs.directory(aabDirectory).createSync(recursive: true);
fs.file(fs.path.join(aabDirectory.path, 'app.aab')).writeAsStringSync('irrelevant');
final File bundle = findBundleFile(gradleProject, const BuildInfo(BuildMode.profile, 'foo'));
expect(bundle, isNotNull);
expect(bundle.path, '/fooProfile/app.aab');
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
});
testUsingContext('Finds app bundle when no flavor is used in profile mode', () {
final GradleProject gradleProject = MockGradleProject();
when(gradleProject.bundleDirectory).thenReturn(fs.currentDirectory);
when(gradleProject.bundleFileFor(any)).thenReturn('app.aab');
final Directory aabDirectory = gradleProject.bundleDirectory.childDirectory('profile');
fs.directory(aabDirectory).createSync(recursive: true);
fs.file(fs.path.join(aabDirectory.path, 'app.aab')).writeAsStringSync('irrelevant');
final File bundle = findBundleFile(gradleProject, const BuildInfo(BuildMode.profile, null));
expect(bundle, isNotNull);
expect(bundle.path, '/profile/app.aab');
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
});
}); });
group('gradle project', () { group('gradle project', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment