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:
The ScreenShot for the Android Studio Production folder is the following.
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.
Apply the Google Services plugin at the end of the build.gradle (Module: app) file:
apply plugin: 'com.google.gms.google-services'
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.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Machine Learning frameworks like PyTorch and Tensorflow is a testament to his versatility and commitment to the craft.