shkschneider
shkschneider

Reputation: 18243

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.

Upvotes: 27

Views: 13616

Answers (3)

G00fY
G00fY

Reputation: 5297

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")
      ...

Upvotes: 59

Roman Tikhonov
Roman Tikhonov

Reputation: 81

What actually worked for me is enabling "Android Studio Preferences -> Experimental -> Only sync the active variant". It keeps the selected build variant when reopening AS or when re-syncing, basically solving the original problem.

AS/AGP v4.1.

Upvotes: 0

TibiG
TibiG

Reputation: 849

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

Upvotes: 4

Related Questions