We have an Android project that uses the new Gradle build system, and we use Android Studio as a development tool. When there are several product flavors specified in build.gradle
, we notice that Android Studio builds the first one specified alphabetically. Is there a way to tell Android Studio to build and test only a specific product flavor during development?
6 Answers
On the lower left of the Studio window there's a docked view called "Build Variants".
Open it and choose whichever variant you want to work on. This will impact which variant is built but also the enabled source folders, which will drive completion in code and resources editors.

- 28,383
- 5
- 88
- 64
-
16Cool. Is there a way to customize which one it prefers upon initial import? – Joe Jul 17 '13 at 11:42
-
3I don't think so. I can ask the engineer who did it if we can add this. But this is likely to be different per project if you have flavors. – Xavier Ducrohet Jul 17 '13 at 17:00
-
1Sure, thanks. Our issue is that we develop on flavor `dev` but we need to deploy flavor `demo`, which alphabetically higher than `dev`. Selecting the build variant is a solid workaround though. – Joe Jul 17 '13 at 17:07
-
2Hm, this panel only selects build variant, not product flavor. Any way of getting Android to run a variant? – Kenneth Oct 28 '13 at 12:14
-
35Variants are a combination of flavor(s) and build types. You can only deploy variants. You can never build an apk that's only a flavor. – Xavier Ducrohet Dec 23 '13 at 18:20
-
1Worth mentioning that when you "Generate a signed APK", you will automatically be prompted to select the flavor. – Eduard Luca Feb 20 '15 at 15:48
-
5If you interested, you can use command line to build specified variant: ./gradlew assemble
– Deepscorn Apr 25 '15 at 10:16<...> , e.g. assembleGooglePlayRelease. And you can build and install on connected device or emulator using: ./gradlew install <...> -
7But with which product flavor, does Android studio build the application by default? – Malwinder Singh May 24 '15 at 09:03
-
1@Malwinder, by default the app is built with an empty flavor, if there are others - it builts them in ascending order. For specifying the default build variant, there is an [issue logged](https://code.google.com/p/android/issues/detail?id=64917). – lomza Apr 18 '16 at 07:21
-
1This allows you so select the build variant to build, but not the product flavor, which is what the OP is asking about. Is there a way to determine which FLAVOR is used? – David Berry Aug 22 '16 at 17:39
-
5I would be interested if there is a way to define the build flavor, which is selected by default when checking out the project. currently it selects the second flavor and second buildtype, but would like to define it my way – da_berni Aug 26 '16 at 10:27
-
1In Android Studio 3.5 you will be able to put `isDefault true` in the buildtype in build.gradle, like this: `android { buildTypes { dev { isDefault true } } }` – Someone Somewhere May 17 '19 at 13:01
-
mm so hidden :/ – javier_domenech Feb 20 '20 at 15:48
-
@SomeoneSomewhere looks like that does not work for product flavors – Den Drobiazko Mar 24 '21 at 17:52
Currently there appears to be no way to select default flavor. There is a feature request in Android Issue Tracker for it:
https://code.google.com/p/android/issues/detail?id=64917
You can star/vote the request, so it gets higher priority on Android development tools backlog.

- 2,458
- 1
- 25
- 48
-
4this feature will be in Android Studio 3.5. NO JOKE - this took 5 years to implement !! (look at the ticket creation date) – Someone Somewhere May 17 '19 at 12:57
Yes, there is a way:
android {
productFlavors {
foo {
isDefault true
}
}
}
And otherwise variants with the debug build type are favoured.
It was added in Android Studio 3.5, see feature request:
"Included in Android Gradle Plugin 3.5.0-alpha08 and Android Studio 3.5 Canary 8 [3.5.0.7].
The heuristic for projects using older AGP and projects without explicit settings has also been updated to favour variants with the build type debug, as described in the commit message."

- 1
- 1

- 191
- 1
- 6
-
2isDefault is declared as final and there’s no setter available. However we can use isDefault.set(true) – M.Paunov Aug 18 '20 at 07:47
-
-
maybe this doesn't work with gradle.kts scripts or smth - does nothing in our project – Den Drobiazko Mar 24 '21 at 17:54
On latest of android studio, on menu bar, go to Build
> Select build Variant
, if it's greyed out (disabled), open the project directory and then open the app
section then go to that button again. After you've clicked on it, it will open up a window on the sidebar called Build Variants, from there you can select which build variant you want to build, then click on debug and it will build the variant you selected.

- 1,114
- 13
- 21
What actually worked for me is enabling "Android Studio Preferences -> Experimental -> Only sync the active variant". After you select the desired build variant once, AS will keep the selected build variant when reopening or when re-syncing the project, basically solving the original problem.
AS/AGP v4.1.

- 81
- 1
- 4
You can specify the command run In Section Before launch Gradle-aware Make
You can list all gradle tasks by gradlew tasks

- 337
- 2
- 11
-
I tried this and while it certainly does result in only one flavor being built, Android Studio will still only launch the selected variant. Worse, if I select a specific Activity not in the selected variant , then I get a confusing error message saying "the activity must be exported or contain an intent-filter". The error goes away once I change the build bariant selection. – Dagmar Jun 26 '18 at 11:23