Victor Santiago Victor Santiago - 5 months ago 82
Android Question

Do I need a new google-services.json for each productFlavor?

So, I'm building a set of applications from a single code base, and I'm using productFlavors to customize each app.

Each flavor will need to have its own tracking ID for Google Analytics, so I started generating a new google-services.json for each flavor, and I found out that there's a limit at the Google Developer Console.

The question is, how can I use the same json file for all the flavors? (Each flavor has its own applicationID)

Or what are my alternatives? I only need to get the Analytics tracking working, and that's pretty much why I even started using the file in the first place.

I thought about editing manually each file to change its package_name and tracking_id, but I'm not sure that's a viable option for production...

Answer

So I kept looking into it, and turns out you don't really need one new google-services.json for each flavor.

It doesn't seem that much intuitive at first, but when you're creating the json file, you need to set the same App name for all flavors, just different package names.

E.g.: When you're in this step, the app name would be MyApp, and the package name my.app.free.

Proceed until the end where you get to the step where you download the file. Then, just go to that step again, and now set the same App Name (in this example MyApp), but with the new package name (e.g.: my.app.pro).

When you download the new google-services.json, it will be set up for both packages, and with different analytics.

Comments