1
1

More than 1 year has passed since last update.

Android Gradle: デフォルトの buildType / productFlavor を指定する

Last updated at Posted at 2022-01-18

Android Studio で Gradle プロジェクトを開いたとき、なにも指定がなければ、buildType / productFlavor を辞書順で並べたときの先頭の組が選択されます。

初期選択したい buildType / productFlavor があれば isDefault を設定します。

  • Android Gradle Plugin 7.0.4 で確認しています

設定

app/build.gradle.kts

android {
    // ...
    buildTypes {
        getByName("debug") {
            isDefault = true
            // ...
        }
        register("release") {
            // ...
        }
    }
    productFlavors {
        register("develop") {
            isDefault = true
            // ...
        }
        register("alpha") {
            // ...
        }
        register("production") {
            // ...
        }
    }
    // ...
}

デフォルトの buildType / productFlavor を指定するには ApplicationBuildType#isDefaultApplicationProductFlavor#isDefault を設定します。

上記設定であれば、developDebug がデフォルトとして選択されるようになります。

buildType が debug, release であり、productFlavor が alpha, develop, production であれば、Build Variant は以下のように辞書順で並びます。

  • buildType: debug -> release
  • productFlavor: alpha -> develop -> production
  • Build Variant: alphaDebug -> alphaRelease -> developDebug -> developRelease -> productionDebug -> productionRelease

isDefault の設定がなければ、先頭の alphaDebug がデフォルトで選択されます。

image.png

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1