Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make multiple app flavors use the same google-services.json file?

I would like to have one google-services.json file, with one application ID, connected to one Firebase "app" in one Firebase "project," used by a variety of flavors of my Android app.

My flavors are branded differently, but they work very much the same, and I want the analytics data from all of them to end up in the same place in Firebase. However, they all (of course) have Android application IDs/package names that are suffixed differently, and none of those flavor package names match the one in the google-services.json, which doesn't have a suffix at all.

I've seen many ways to connect different flavors of an Android app to different Firebase "apps" in the same Firebase "project," but that's not what I want to do: I want to connect different Android app flavors to the same Firebase "app."

Is there a way to do this with Firebase, or should I look elsewhere?

Thanks, Dan Wiebe

like image 306
Dan Wiebe Avatar asked Aug 14 '17 19:08

Dan Wiebe


People also ask

How do I use a different Google-services json file with multiple product flavors Android?

Usage: How to use this file for different product flavors. There are only 3 steps first step is so simple just remove the google-service. json file from the root of the app/ module and save it your local system directory for the save side, & then make your product flavors like Production & Staging environment.

How can I add two Google-services json in the same project?

There is no way to use two google-services. json files in a single Android app. The file name is the same between them and they need to be in the same location. So one will overwrite the other in that case.

How do you maintain two Google-services json production and debugging?

Place your google-services. json file in your $projectName/app/src/$buildType directory. For example, place one json file in src/release and another in src/debug . You will likely need to create the release & debug folders.

How do I add Google-services to json app?

Get config file for your Android appIn the Your apps card, select the package name of the app for which you need a config file. Click google-services. json. Move your config file into the module (app-level) directory of your app.


Video Answer


1 Answers

Indeed my previous answer was not enough to answer your question so I've created an step by step guide.

Step by Step

  1. Build the application with the product flavor you want as default.

  2. Remove the apply plugin: 'com.google.gms.google-services from your app/build.gradle. This plugin reads the values in google-services.json and copies them on compile time in an xml values file. We will do this manually in step 4.

  3. Create a new (or use an existing) xml values file in the main folder.

  4. Go to app/build/generated/res/google-services/{productFlavor}/debug/values/values.xml and copy those values into the values xml created in Step 3. Replace {productFlavor} with the product flavor selected into Step 1.

  5. Delete the google-services.json

Now the credentials from your default application will be used and you don't need to initialise the way I mentioned in my previous answer

like image 191
Martin Metselaar Avatar answered Nov 14 '22 22:11

Martin Metselaar