On Android when there are multiple flavors and no --flavor flag is specified then use a default one #22856
Copy link
Copy link
Closed
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityt: gradle"flutter build" and "flutter run" on Android"flutter build" and "flutter run" on Androidteam-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool teamTriaged by Flutter Tool team
Description
On Android, when there are multiple flavors defined, and the user runs the app but does not specify a value for the --flavor flag then the following error is shown:
You must specify a --flavor option to select one of them.
This is implemented like that here: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/android/gradle.dart#L342
This makes it so that everytime we have to specifiy a value for --flavor.
I would propose when the flag is not specified to just default to the first one.
This will make it faster to start your Flutter app, not having to write --flavor _flavor_ everytime.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityt: gradle"flutter build" and "flutter run" on Android"flutter build" and "flutter run" on Androidteam-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool teamTriaged by Flutter Tool team
Activity
matthewcook333 commentedon Dec 7, 2018
Also running into this issue, it is a pain to not be able to just run with default commands. Would be nice to have a default flavor.
royorange commentedon Feb 14, 2019
+1 Also face the same issue.
bradyt commentedon Aug 19, 2019
@cmwarrington, do you know if flutter should be able to move forward on this? I saw your involvement at the following commits, and made a naive guess you might have an idea for this.
mewadaArvind commentedon Oct 11, 2019
Also face the same issue. please give a answer this question.
jackyhieu1211-hn commentedon Mar 4, 2020
Hello. I have the same problem.
I fixed it the following way
I use Android Studio.
open Edit Configurations -> build flavor -> enter flavor name (example : develop)
erabti commentedon May 19, 2020
Any work around for this? This is really needed for us.
msmaromi commentedon May 20, 2020
in vscode you can setup debug configuration
jackyhieu1211-hn commentedon May 20, 2020
@erabti If you use Android Studio. You can try my way.
open Edit Configurations -> build flavor -> enter flavor name (example : develop)
nazdream commentedon Apr 13, 2021
Does anybody know how to set default flavor in Bitrise? I am getting the same error when Bitrise is trying to build the app, and I can't find a way to set flavor.
11 remaining items
marianhlavac commentedon Jul 10, 2023
Can this be given a higher priority? This is confusing for almost everyone onboarding a project having flavors, especially when iOS behaves differently, and especially when Flutter gives cryptic error messages that doesn't suggest the flavor is missing?
pattobrien commentedon Aug 2, 2023
Here's the cryptic message in question:
This is not a helpful message in the slightest, especially because there is an apk file in that directory, it's just not the name expected.
If a default flavor cannot be selected, then it would be helpful to at least mention what the expected file name is, so that a user can easily spot the difference between the file that does exist vs. the file that the flutter tool is expecting. This seems like a quick win IMO.
vietstone-ng commentedon Aug 8, 2023
Please support this
giljulio commentedon Aug 16, 2023
Not a default, but if you rather make the issue more explicit - you can use the following code to fail the build when it's not specified
SilenceCodder commentedon Oct 7, 2023
Does this error mean that it's missing a Flavor name?
Can't the project run by default using
flutter runcommand?slaci commentedon Feb 12, 2024
I just bumped into this and with flutter 3.16.x (and gradle 8.2) flutter picks a default flavor (I don't know since which version).
By default gradle sorts the flavor names in alphabetical order and picks the first one. Seems like flutter only supports this.In Gradle it is possible to mark a flavor as default, but from my tests flutter ignores it:
When defining this I would expect
bas the default, but when running the app withflutter runthen it picksainstead.Edit: The alphabetical order trick worked randomly only, could not reproduce between two full builds. So I reduce my points to just: the gradle
isDefaultsetting is ignored. So a default flavor is indeed picked, but I can't figure out how to control which one.ChaseGuru commentedon May 10, 2024
Why setting a default doesn't work
Flutter seems to by default do all flavors.
Contrarily though, appbundle seems to only produce one.
flutter run also fails for me without a flavor
hasanm08 commentedon May 11, 2024
can you please merge this PR? #147968
add `default-flavor` field to flutter pubspec, which will be used as …
document default flavor (#10642)
andrewkolos commentedon May 22, 2024
#147968 will allow users to specify a
default-flavorin their pubspec and should be available in the next stable release (whatever comes after 3.22). I believe this satisfies the primary concern/request of this issue.#139286 tracks the issue of the confusing error message shown when an Android-enabled project has flavors configured but
--flavoris not provided.add `default-flavor` field to flutter pubspec, which will be used as …
github-actions commentedon Jun 5, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.