diff --git a/packages/flutter_tools/lib/src/android/gradle.dart b/packages/flutter_tools/lib/src/android/gradle.dart index 193eff60f2..b75cb5f33b 100644 --- a/packages/flutter_tools/lib/src/android/gradle.dart +++ b/packages/flutter_tools/lib/src/android/gradle.dart @@ -91,7 +91,7 @@ String getAarTaskFor(BuildInfo buildInfo) { /// For example, when [splitPerAbi] is true, multiple APKs are created. Iterable _apkFilesFor(AndroidBuildInfo androidBuildInfo) { final String buildType = camelCase(androidBuildInfo.buildInfo.modeName); - final String productFlavor = androidBuildInfo.buildInfo.flavor ?? ''; + final String productFlavor = androidBuildInfo.buildInfo.lowerCasedFlavor ?? ''; final String flavorString = productFlavor.isEmpty ? '' : '-$productFlavor'; if (androidBuildInfo.splitPerAbi) { return androidBuildInfo.targetArchs.map((AndroidArch arch) { @@ -901,7 +901,7 @@ Iterable listApkPaths( final String buildType = camelCase(androidBuildInfo.buildInfo.modeName); final List apkPartialName = [ if (androidBuildInfo.buildInfo.flavor?.isNotEmpty ?? false) - androidBuildInfo.buildInfo.flavor, + androidBuildInfo.buildInfo.lowerCasedFlavor, '$buildType.apk', ]; if (androidBuildInfo.splitPerAbi) { @@ -938,7 +938,7 @@ File findBundleFile(FlutterProject project, BuildInfo buildInfo) { // the directory name is `foo_barRelease`. fileCandidates.add( getBundleDirectory(project) - .childDirectory('${buildInfo.flavor}${camelCase('_' + buildInfo.modeName)}') + .childDirectory('${buildInfo.lowerCasedFlavor}${camelCase('_' + buildInfo.modeName)}') .childFile('app.aab')); // The Android Gradle plugin 3.5.0 adds the flavor name to file name. @@ -946,8 +946,8 @@ File findBundleFile(FlutterProject project, BuildInfo buildInfo) { // the file name name is `app-foo_bar-release.aab`. fileCandidates.add( getBundleDirectory(project) - .childDirectory('${buildInfo.flavor}${camelCase('_' + buildInfo.modeName)}') - .childFile('app-${buildInfo.flavor}-${buildInfo.modeName}.aab')); + .childDirectory('${buildInfo.lowerCasedFlavor}${camelCase('_' + buildInfo.modeName)}') + .childFile('app-${buildInfo.lowerCasedFlavor}-${buildInfo.modeName}.aab')); } for (final File bundleFile in fileCandidates) { if (bundleFile.existsSync()) { diff --git a/packages/flutter_tools/lib/src/build_info.dart b/packages/flutter_tools/lib/src/build_info.dart index 04dadab3d4..9611fc2155 100644 --- a/packages/flutter_tools/lib/src/build_info.dart +++ b/packages/flutter_tools/lib/src/build_info.dart @@ -152,6 +152,10 @@ class BuildInfo { String get modeName => getModeName(mode); String get friendlyModeName => getFriendlyModeName(mode); + /// the flavor name in the output files is lowercased (see flutter.gradle), + /// so the lower cased flavor name is used to compute the output file name + String get lowerCasedFlavor => flavor?.toLowerCase(); + /// Convert to a structued string encoded structure appropriate for usage as /// environment variables or to embed in other scripts. /// diff --git a/packages/flutter_tools/test/general.shard/android/gradle_test.dart b/packages/flutter_tools/test/general.shard/android/gradle_test.dart index 6129b3db1e..753043f02c 100644 --- a/packages/flutter_tools/test/general.shard/android/gradle_test.dart +++ b/packages/flutter_tools/test/general.shard/android/gradle_test.dart @@ -152,6 +152,13 @@ void main() { expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barRelease', 'app.aab')); }); + testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in release mode', () { + final FlutterProject project = generateFakeAppBundle('foo_barRelease', 'app.aab', fileSystem); + final File bundle = findBundleFile(project, const BuildInfo(BuildMode.release, 'foo_Bar', treeShakeIcons: false)); + expect(bundle, isNotNull); + expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barRelease', 'app.aab')); + }); + testWithoutContext("Finds app bundle when flavor doesn't contain underscores in release mode", () { final FlutterProject project = generateFakeAppBundle('fooRelease', 'app.aab', fileSystem); final File bundle = findBundleFile(project, const BuildInfo(BuildMode.release, 'foo', treeShakeIcons: false)); @@ -159,6 +166,13 @@ void main() { expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooRelease', 'app.aab')); }); + testWithoutContext("Finds app bundle when flavor doesn't contain underscores but contains uppercase letters in release mode", () { + final FlutterProject project = generateFakeAppBundle('fooaRelease', 'app.aab', fileSystem); + final File bundle = findBundleFile(project, const BuildInfo(BuildMode.release, 'fooA', treeShakeIcons: false)); + expect(bundle, isNotNull); + expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooaRelease', 'app.aab')); + }); + testWithoutContext('Finds app bundle when no flavor is used in release mode', () { final FlutterProject project = generateFakeAppBundle('release', 'app.aab', fileSystem); final File bundle = findBundleFile(project, const BuildInfo(BuildMode.release, null, treeShakeIcons: false)); @@ -173,6 +187,13 @@ void main() { expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barDebug', 'app.aab')); }); + testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in debug mode', () { + final FlutterProject project = generateFakeAppBundle('foo_barDebug', 'app.aab', fileSystem); + final File bundle = findBundleFile(project, const BuildInfo(BuildMode.debug, 'foo_Bar', treeShakeIcons: false)); + expect(bundle, isNotNull); + expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barDebug', 'app.aab')); + }); + testWithoutContext("Finds app bundle when flavor doesn't contain underscores in debug mode", () { final FlutterProject project = generateFakeAppBundle('fooDebug', 'app.aab', fileSystem); final File bundle = findBundleFile(project, const BuildInfo(BuildMode.debug, 'foo', treeShakeIcons: false)); @@ -180,6 +201,13 @@ void main() { expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooDebug', 'app.aab')); }); + testWithoutContext("Finds app bundle when flavor doesn't contain underscores but contains uppercase letters in debug mode", () { + final FlutterProject project = generateFakeAppBundle('fooaDebug', 'app.aab', fileSystem); + final File bundle = findBundleFile(project, const BuildInfo(BuildMode.debug, 'fooA', treeShakeIcons: false)); + expect(bundle, isNotNull); + expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooaDebug', 'app.aab')); + }); + testWithoutContext('Finds app bundle when no flavor is used in debug mode', () { final FlutterProject project = generateFakeAppBundle('debug', 'app.aab', fileSystem); final File bundle = findBundleFile(project, const BuildInfo(BuildMode.debug, null, treeShakeIcons: false)); @@ -194,6 +222,13 @@ void main() { expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barProfile', 'app.aab')); }); + testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in profile mode', () { + final FlutterProject project = generateFakeAppBundle('foo_barProfile', 'app.aab', fileSystem); + final File bundle = findBundleFile(project, const BuildInfo(BuildMode.profile, 'foo_Bar', treeShakeIcons: false)); + expect(bundle, isNotNull); + expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barProfile', 'app.aab')); + }); + testWithoutContext("Finds app bundle when flavor doesn't contain underscores in profile mode", () { final FlutterProject project = generateFakeAppBundle('fooProfile', 'app.aab', fileSystem); final File bundle = findBundleFile(project, const BuildInfo(BuildMode.profile, 'foo', treeShakeIcons: false)); @@ -201,6 +236,13 @@ void main() { expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooProfile', 'app.aab')); }); + testWithoutContext("Finds app bundle when flavor doesn't contain underscores but contains uppercase letters in profile mode", () { + final FlutterProject project = generateFakeAppBundle('fooaProfile', 'app.aab', fileSystem); + final File bundle = findBundleFile(project, const BuildInfo(BuildMode.profile, 'fooA', treeShakeIcons: false)); + expect(bundle, isNotNull); + expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooaProfile', 'app.aab')); + }); + testWithoutContext('Finds app bundle when no flavor is used in profile mode', () { final FlutterProject project = generateFakeAppBundle('profile', 'app.aab', fileSystem); final File bundle = findBundleFile(project, const BuildInfo(BuildMode.profile, null, treeShakeIcons: false)); @@ -236,6 +278,13 @@ void main() { expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barRelease', 'app-foo_bar-release.aab')); }); + testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in release mode - Gradle 3.5', () { + final FlutterProject project = generateFakeAppBundle('foo_barRelease', 'app-foo_bar-release.aab', fileSystem); + final File bundle = findBundleFile(project, const BuildInfo(BuildMode.release, 'foo_Bar', treeShakeIcons: false)); + expect(bundle, isNotNull); + expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barRelease', 'app-foo_bar-release.aab')); + }); + testWithoutContext('Finds app bundle when flavor contains underscores in profile mode - Gradle 3.5', () { final FlutterProject project = generateFakeAppBundle('foo_barProfile', 'app-foo_bar-profile.aab', fileSystem); final File bundle = findBundleFile(project, const BuildInfo(BuildMode.profile, 'foo_bar', treeShakeIcons: false)); @@ -243,9 +292,9 @@ void main() { expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barProfile', 'app-foo_bar-profile.aab')); }); - testWithoutContext('Finds app bundle when flavor contains underscores in debug mode - Gradle 3.5', () { + testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in debug mode - Gradle 3.5', () { final FlutterProject project = generateFakeAppBundle('foo_barDebug', 'app-foo_bar-debug.aab', fileSystem); - final File bundle = findBundleFile(project, const BuildInfo(BuildMode.debug, 'foo_bar', treeShakeIcons: false)); + final File bundle = findBundleFile(project, const BuildInfo(BuildMode.debug, 'foo_Bar', treeShakeIcons: false)); expect(bundle, isNotNull); expect(bundle.path, fileSystem.path.join('irrelevant','app', 'outputs', 'bundle', 'foo_barDebug', 'app-foo_bar-debug.aab')); }); @@ -296,6 +345,14 @@ void main() { expect(apks, ['app-flavor1-release.apk']); }); + testWithoutContext('Finds APK with flavor in release mode', () { + final Iterable apks = listApkPaths( + const AndroidBuildInfo(BuildInfo(BuildMode.release, 'flavorA', treeShakeIcons: false)), + ); + + expect(apks, ['app-flavora-release.apk']); + }); + testWithoutContext('Finds APK with flavor in release mode - AGP v3', () { final Iterable apks = listApkPaths( const AndroidBuildInfo(BuildInfo(BuildMode.release, 'flavor1', treeShakeIcons: false)), @@ -315,6 +372,19 @@ void main() { 'app-x86_64-flavor1-release.apk', ])); }); + + testWithoutContext('Finds APK with split-per-abi when flavor contains uppercase letters', () { + final Iterable apks = listApkPaths( + const AndroidBuildInfo(BuildInfo(BuildMode.release, 'flavorA', treeShakeIcons: false), splitPerAbi: true), + ); + + expect(apks, unorderedEquals([ + 'app-armeabi-v7a-flavora-release.apk', + 'app-arm64-v8a-flavora-release.apk', + 'app-x86_64-flavora-release.apk', + ])); + }); + }); group('gradle build', () {