Unverified Commit 1fcb076e authored by Michael Tamm's avatar Michael Tamm Committed by GitHub

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

parent 4b82d47b
......@@ -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()) {
......
......@@ -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);
}
......@@ -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();
......
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