mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
Teach the flutter tool how to find android output files if the flavor contains uppercase letters (#66687)
This changes the name of the generated output files on android in case a flavor with uppercase letters is used. Previously, the lowercased flavor name would be used for the apk/aab file. Now, the flavor name is used as-is.
This commit is contained in:
parent
31254fbe03
commit
8e9e13449b
|
@ -91,7 +91,7 @@ String getAarTaskFor(BuildInfo buildInfo) {
|
|||
/// For example, when [splitPerAbi] is true, multiple APKs are created.
|
||||
Iterable<String> _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<String>((AndroidArch arch) {
|
||||
|
@ -901,7 +901,7 @@ Iterable<String> listApkPaths(
|
|||
final String buildType = camelCase(androidBuildInfo.buildInfo.modeName);
|
||||
final List<String> apkPartialName = <String>[
|
||||
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()) {
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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, <String>['app-flavor1-release.apk']);
|
||||
});
|
||||
|
||||
testWithoutContext('Finds APK with flavor in release mode', () {
|
||||
final Iterable<String> apks = listApkPaths(
|
||||
const AndroidBuildInfo(BuildInfo(BuildMode.release, 'flavorA', treeShakeIcons: false)),
|
||||
);
|
||||
|
||||
expect(apks, <String>['app-flavora-release.apk']);
|
||||
});
|
||||
|
||||
testWithoutContext('Finds APK with flavor in release mode - AGP v3', () {
|
||||
final Iterable<String> 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<String> apks = listApkPaths(
|
||||
const AndroidBuildInfo(BuildInfo(BuildMode.release, 'flavorA', treeShakeIcons: false), splitPerAbi: true),
|
||||
);
|
||||
|
||||
expect(apks, unorderedEquals(<String>[
|
||||
'app-armeabi-v7a-flavora-release.apk',
|
||||
'app-arm64-v8a-flavora-release.apk',
|
||||
'app-x86_64-flavora-release.apk',
|
||||
]));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
group('gradle build', () {
|
||||
|
|
Loading…
Reference in a new issue