Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Android Studio's default build flavor?

I got a project configured with multiple variants and flavors:

buildTypes {
    debug {
    }
    release {
    }
}
flavorDimensions "default"
productFlavors {
    mock {
    }
    alpha {
    }
    beta {
    }
    prod {
    }
}

Whenever I open the project from another one (so starting Android Studio), it selects the mockDebug variant by default. Often I end up build this one first, then realizing I'm on the wrong variant.

Is there a way to tell Android Studio to defaults to one variant, let's say betaDebug?

Technicals: Android Studio 3.1.4, Gradle wrapper 4.4, Android Gradle 3.1.4.

like image 397
shkschneider Avatar asked Aug 29 '18 07:08

shkschneider


People also ask

What is Flavour dimension Android?

The flavor dimensions define the cartesian product that will be used to produce variants. Example: flavorDimensions("dimA", "dimB") productFlavors { row1 { ... dimension = "dimA" } row2 { ... dimension = "dimA" } row3 { ... dimension = "dimA" } col1 { ...

When would you use a product Flavour in your build setup?

When to use Product Flavors. When we want to address the issue of having separate project code for each version of the app while still having one project code. Given a scenario where you have a free and a paid app you can limit features in the free and expose all the other features in the paid version of the app.

What is BuildConfig flavor?

BuildConfig.FLAVOR gives you combined product flavor. So if you have only one flavor dimension: productFlavors { normal { } admin { } } Then you can just check it: if (BuildConfig. FLAVOR.


2 Answers

With Android Studio 3.5+ you can set default falvors:

android {
  flavorDimensions "stage", "target"
  productFlavors {
    develop {
      getIsDefault().set(true) // that does the magic
      dimension "stage"
      ...

When using KTS it lookes like this:

android {
  flavorDimensions("stage", "target")
  productFlavors {
    create("develop") {
      isDefault = true
      dimension("stage")
      ...
like image 142
G00fY Avatar answered Sep 19 '22 19:09

G00fY


Change the order in which you define them in productFlavors. The IDE always loads the first flavor it finds there as the default.

like image 20
TibiG Avatar answered Sep 20 '22 19:09

TibiG