15
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Flutter】flavorで環境ごとに、google-services.json や アプリID, アプリ名を切り替える

Posted at

アプリID, アプリ名をflavorで分ける

android/app/build.gradle配下のファイルにproductFlavorsを追加する。

android/app/build.gradle

...

android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        ...
    }

    buildTypes {
        ...
    }

    flavorDimensions "app"
    productFlavors {
        dev {
            dimension "app"
            resValue "string", "app_name", "DEV_{アプリ名}"
            applicationId "{開発環境のID}.dev"
        }
        qa {
            dimension "app"
            resValue "string", "app_name", "{アプリ名}"
            applicationId "{QA環境のID}"
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    ...
}

ちなみに、android/app/src/flavor名/res/values/strings.xmlからアプリ名を変更する方法は上手く変更できませんでした。

google-service.jsonを環境ごとに切り替える方法

android/app/src配下にflavor名のフォルダを作成し、'google-service.json'の名前でconfigファイルを設定すると、flavorを指定してbuildした際にそのディレクトリを参照してくれます。

そのため、以下のようにディレクトリを配置するだけで、flavorごとのfirebaseの設定ファイルの切り分けは完了です。

app
└── src
    ├── main
    │   ├── AndroidManifest.xml
    │   ├── java
    │   ├── kotlin
    │   └── res
    ├── dev
    │   └── google-servicesjson.json
    ├── qa
    │   └── google-services.json
    └── prd
        └── google-services.json

参考記事

15
8
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
15
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?