Skip to content

Commit 1fcb076

Browse files
authored
[flutter_tools] Fix bundle file not found when flavor contains upperc… (#92660)
1 parent 4b82d47 commit 1fcb076

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

packages/flutter_tools/lib/src/android/gradle.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,11 @@ File findBundleFile(FlutterProject project, BuildInfo buildInfo, Logger logger,
873873
getBundleDirectory(project)
874874
.childDirectory('${buildInfo.lowerCasedFlavor}${camelCase('_${buildInfo.modeName}')}')
875875
.childFile('app-${buildInfo.lowerCasedFlavor}-${buildInfo.modeName}.aab'));
876+
877+
// The Android Gradle plugin 4.1.0 does only lowercase the first character of flavor name.
878+
fileCandidates.add(getBundleDirectory(project)
879+
.childDirectory('${buildInfo.uncapitalizedFlavor}${camelCase('_${buildInfo.modeName}')}')
880+
.childFile('app-${buildInfo.uncapitalizedFlavor}-${buildInfo.modeName}.aab'));
876881
}
877882
for (final File bundleFile in fileCandidates) {
878883
if (bundleFile.existsSync()) {

packages/flutter_tools/lib/src/build_info.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,14 @@ class BuildInfo {
193193
String get modeName => getModeName(mode);
194194
String get friendlyModeName => getFriendlyModeName(mode);
195195

196-
/// the flavor name in the output files is lower-cased (see flutter.gradle),
196+
/// the flavor name in the output apk files is lower-cased (see flutter.gradle),
197197
/// so the lower cased flavor name is used to compute the output file name
198198
String? get lowerCasedFlavor => flavor?.toLowerCase();
199199

200+
/// the flavor name in the output bundle files has the first character lower-cased,
201+
/// so the uncapitalized flavor name is used to compute the output file name
202+
String? get uncapitalizedFlavor => _uncapitalize(flavor);
203+
200204
/// Convert to a structured string encoded structure appropriate for usage
201205
/// in build system [Environment.defines].
202206
///
@@ -1008,3 +1012,10 @@ String getNameForHostPlatformArch(HostPlatform platform) {
10081012
return 'x64';
10091013
}
10101014
}
1015+
1016+
String? _uncapitalize(String? s) {
1017+
if (s == null || s.isEmpty) {
1018+
return s;
1019+
}
1020+
return s.substring(0, 1).toLowerCase() + s.substring(1);
1021+
}

packages/flutter_tools/test/general.shard/android/gradle_find_bundle_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,34 @@ void main() {
305305
expect(bundle.path, '/build/app/outputs/bundle/foo_barDebug/app-foo_bar-debug.aab');
306306
});
307307

308+
testWithoutContext(
309+
'Finds app bundle when flavor contains underscores and uppercase letters in release mode - Gradle 4.1', () {
310+
final FlutterProject project = generateFakeAppBundle('foo_BarRelease', 'app-foo_Bar-release.aab', fileSystem);
311+
final File bundle = findBundleFile(
312+
project,
313+
const BuildInfo(BuildMode.release, 'Foo_Bar', treeShakeIcons: false),
314+
BufferLogger.test(),
315+
TestUsage(),
316+
);
317+
318+
expect(bundle, isNotNull);
319+
expect(bundle.path, '/build/app/outputs/bundle/foo_BarRelease/app-foo_Bar-release.aab');
320+
});
321+
322+
testWithoutContext(
323+
'Finds app bundle when flavor contains underscores and uppercase letters in debug mode - Gradle 4.1', () {
324+
final FlutterProject project = generateFakeAppBundle('foo_BarDebug', 'app-foo_Bar-debug.aab', fileSystem);
325+
final File bundle = findBundleFile(
326+
project,
327+
const BuildInfo(BuildMode.debug, 'Foo_Bar', treeShakeIcons: false),
328+
BufferLogger.test(),
329+
TestUsage(),
330+
);
331+
332+
expect(bundle, isNotNull);
333+
expect(bundle.path, '/build/app/outputs/bundle/foo_BarDebug/app-foo_Bar-debug.aab');
334+
});
335+
308336
testWithoutContext('AAB not found', () {
309337
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
310338
final TestUsage testUsage = TestUsage();

0 commit comments

Comments
 (0)