[flutter_tools] Fix bundle file not found when flavor contains upperc… (#92660)

This commit is contained in:
Michael Tamm 2022-02-04 20:55:20 +01:00 committed by GitHub
parent 4b82d47b01
commit 1fcb076eb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 1 deletions

View File

@ -873,6 +873,11 @@ File findBundleFile(FlutterProject project, BuildInfo buildInfo, Logger logger,
getBundleDirectory(project)
.childDirectory('${buildInfo.lowerCasedFlavor}${camelCase('_${buildInfo.modeName}')}')
.childFile('app-${buildInfo.lowerCasedFlavor}-${buildInfo.modeName}.aab'));
// The Android Gradle plugin 4.1.0 does only lowercase the first character of flavor name.
fileCandidates.add(getBundleDirectory(project)
.childDirectory('${buildInfo.uncapitalizedFlavor}${camelCase('_${buildInfo.modeName}')}')
.childFile('app-${buildInfo.uncapitalizedFlavor}-${buildInfo.modeName}.aab'));
}
for (final File bundleFile in fileCandidates) {
if (bundleFile.existsSync()) {

View File

@ -193,10 +193,14 @@ class BuildInfo {
String get modeName => getModeName(mode);
String get friendlyModeName => getFriendlyModeName(mode);
/// the flavor name in the output files is lower-cased (see flutter.gradle),
/// the flavor name in the output apk files is lower-cased (see flutter.gradle),
/// so the lower cased flavor name is used to compute the output file name
String? get lowerCasedFlavor => flavor?.toLowerCase();
/// the flavor name in the output bundle files has the first character lower-cased,
/// so the uncapitalized flavor name is used to compute the output file name
String? get uncapitalizedFlavor => _uncapitalize(flavor);
/// Convert to a structured string encoded structure appropriate for usage
/// in build system [Environment.defines].
///
@ -1008,3 +1012,10 @@ String getNameForHostPlatformArch(HostPlatform platform) {
return 'x64';
}
}
String? _uncapitalize(String? s) {
if (s == null || s.isEmpty) {
return s;
}
return s.substring(0, 1).toLowerCase() + s.substring(1);
}

View File

@ -305,6 +305,34 @@ void main() {
expect(bundle.path, '/build/app/outputs/bundle/foo_barDebug/app-foo_bar-debug.aab');
});
testWithoutContext(
'Finds app bundle when flavor contains underscores and uppercase letters in release mode - Gradle 4.1', () {
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),
BufferLogger.test(),
TestUsage(),
);
expect(bundle, isNotNull);
expect(bundle.path, '/build/app/outputs/bundle/foo_BarRelease/app-foo_Bar-release.aab');
});
testWithoutContext(
'Finds app bundle when flavor contains underscores and uppercase letters in debug mode - Gradle 4.1', () {
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),
BufferLogger.test(),
TestUsage(),
);
expect(bundle, isNotNull);
expect(bundle.path, '/build/app/outputs/bundle/foo_BarDebug/app-foo_Bar-debug.aab');
});
testWithoutContext('AAB not found', () {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final TestUsage testUsage = TestUsage();