0
0

More than 1 year has passed since last update.

各ProductFlavorsによって使用するAPIエンドポイントを変えたい

Posted at

初めに

前回の記事で書くBuildTypeによって要素を変更する処理を紹介したので、今回はProductFlavorsによって変更する処理を書いていこうと思います。

本文

前回同様build.gradleに書いていきます

    productFlavors {
        register("stg") {
            buildConfigField(
                "String",
                "API_ENDPOINT",
                "\"api_end_point/\""
            )
        }
        register("prd") {
            buildConfigField(
                "String",
                "API_ENDPOINT", 
                "\"api_end_point\""
            )
        }
    }

上記はbuild.gradlekotlin化している場合の書き方です。
していない場合は下記のように書けば大丈夫です

    productFlavors {
        stg {
            buildConfigField(
                "String",
                "API_ENDPOINT",
                "\"api_end_point/\""
            )
        }
        prd {
            buildConfigField(
                "String",
                "API_ENDPOINT", 
                "\"api_end_point\""
            )
        }
    }

最後に

buildTypesだけだと、課金要素のあるアプリなどを作る時にAPIの制御を気にしないといけなくなるので、今回はproductFlavorsの方も描いてみました。
誰かの役に立てたら光栄です

0
0
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
0
0