1
1

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 5 years have passed since last update.

google-services.jsonをproductFlavorsごとに切り替える方法

Posted at

業務中に使うことがあったので、その備忘録。

やりかた

build.gradleに以下のように記載する

    // GoogleServices.jsonの置き換え
    gradle.taskGraph.beforeTask { Task task ->
        if (task.name ==~ /process.*GoogleServices/) {
            applicationVariants.all { variant ->
                if (task.name ==~ /(?i)process${variant.name}GoogleServices/) {
                    def folderName = "置き換えたいgoogle-services.jsonがおいてあるfolder名"
                    // task.name.consains("xxx")でflavors名を取得して書き換えれる                    
                    copy {
                        from "${folderName}"
                        into "."
                        include "google-services.json"
                    }
                }
            }
        }
    }

これでproductFlavorsが切り替わるごとにgoogle-services.jsonを置き換えることができる

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?