How do I set up multiple Firebase projects with the same bundle ID on Android?

Viewed 1092

I'm working on an Android app that uses Firebase for a few different functions. I'm currently trying to expand from a single Firebase project to 3 to represent development, staging, and production environments.

All of my projects need to use the same bundle ID because of a restriction by another tool I'm using (RevenueCat). What I'm noticing with this setup is that, even when using different google-services.json files, I'm always pointing to my original, production Firebase project.

I've searched around and seen some things about needing to add SHA-1 values on Android to differentiate the apps. I've tried adding the SHA-1 from the app signing key certificate in the Google Play Console to the production project and the SHA-1 from the ./gradlew signingReport output to the staging project. Still no dice, unfortunately.

Does anyone have experience with this kind of setup or any other ideas to try? Thanks so much!

3 Answers

In this case, it turns out I just needed to clear out the app/build folder. Apparently the Firebase configs get "cached" in some way between builds, so clearing it forces it to use the new configuration.

I've just added it as a step in the build process. After this small change, everything is working as expected.

Having several different apps inside one project with the same bundleId/packageName is impossible. You have the possibility to use one google-services.json for several apps, though - you just need to add several apps to your project. The packageName/bundleId of those apps should be different, though.

It is very usual for your case - splitting the app into several flavors to have an appId suffix. For example com.example.app.prod, com.example.app.stage, com.example.app.dev - the suffix can be configure in the gradle.build for each flavor. The issue is that you will have to have different apps inside the firebase project or different projects for each flavor - depending on your needs. For example, when the apps are part of the same project, they will share auth and database storage but will have separate crashlitycs, etc. The different projects will have everything different.

SHA-1 is a bit different thing - it is meant to limit/enable/disable the usage of the APIs based on the signing certificate. There may be several SHA-1 for the same package name. Moreover, SHA-1 only works for Android apps.

What you can do is to create several projects - one for each flavor and register the app under the same package name inside each one - you are able to do that! Each flavor will have to have its own google-services.json file in the appropriate folder.

It works really well with the different package names.

I have never tried this approach with the same packageName, and I don't know the possible drawbacks, so I assume you may face some issues. Or not.

In most of the cases, a simple configuration using google-services.json will be enough for having different Firebase environments in your App. But as we saw, things can get complex very quickly, and depending on the requirements custom ways for configuration and initialization of the Firebase services can be needed. I this article I tried to summarize the different approaches for achieving this goal and share my personal experience. I hope that it was helpful to you and that you enjoyed it.

Related