初めに
前回の記事で書くBuildTypeによって要素を変更する処理を紹介したので、今回はProductFlavorsによって変更する処理を書いていこうと思います。
本文
前回同様build.gradle
に書いていきます
productFlavors {
register("stg") {
buildConfigField(
"String",
"API_ENDPOINT",
"\"api_end_point/\""
)
}
register("prd") {
buildConfigField(
"String",
"API_ENDPOINT",
"\"api_end_point\""
)
}
}
上記はbuild.gradle
をkotlin
化している場合の書き方です。
していない場合は下記のように書けば大丈夫です
productFlavors {
stg {
buildConfigField(
"String",
"API_ENDPOINT",
"\"api_end_point/\""
)
}
prd {
buildConfigField(
"String",
"API_ENDPOINT",
"\"api_end_point\""
)
}
}
最後に
buildTypes
だけだと、課金要素のあるアプリなどを作る時にAPIの制御を気にしないといけなくなるので、今回はproductFlavors
の方も描いてみました。
誰かの役に立てたら光栄です