How to Use a Different google-services.json File with Multiple ProductFlavors

When working with multiple product flavors in Android, you might want to use a different google-services.json file for each flavor. This could be the case when you have different Firebase projects for your development and production environments, for example.

The google-services.json file should be placed in the respective flavor’s directory.

There are only 3 steps.

The first step is so simple just remove the google-service.json file from the root of the app/ module and, save it to your local system directory for the save side, & then make your product flavors like Production & Staging environment.

Step 1

Put each google-services.json file in the respective flavor’s directory. For example, if you have two flavors named dev and prod, your project structure would look like this:

Step 1

The ScreenShot for the Android Studio Production folder is the following.

Android Studio Production folder

Step 2

In your build.gradle (Module: app) file, specify the product flavors:

android {

  flavorDimensions "default"
  productFlavors {
    dev {
      dimension "default"
      applicationIdSuffix ".dev"
      versionNameSuffix "-dev"
   prod {
     dimension "default"
     // no suffix for the production version

Step 3

Now sync your project with Gradle files.

Gradle files.

Apply the Google Services plugin at the end of the build.gradle (Module: app) file:

apply plugin: ''

Now, when you build a flavor, the corresponding google-services.json file will be used.

Remember that each google-services.json file is associated with a specific Firebase project. So if you want to use different Firebase settings or data for each flavor, you will need to set up different Firebase projects and download the corresponding google-services.json file for each one.

Leave a Comment