8

We are integrating firebase messaging in our android application for push notifications. We are going to use SNS from server side to send push message to firebase. Below is our use case:

  • We have three servers: QA, STG and PRODUCTION
  • We created say three projects in firebase console: say appQA, appSTG and appProd
  • But we want to generate only 1 single APK which can receive firebase push notification from any of the above three fire base projects depending on the server to which our user logs-in.
  • We configured each project in firebase and at end we got 1 google-services.json file per project (total 3)
  • Now how do we configure or generate 1 APK which can encompass all three json files and switch between them runtime and not build-time because we do not want to build separate APKs for separate environments. We have a strict requirement of generating one single APK that can be used to connect to all our environments and receive push notifications from all environments.
  • We have tried flavors and build types but both are build-time and not run-time

This is first time that we are venturing in world of push notifications on android.

PS: The obvious solution is to just have one project in firebase and configure it on client and all of our servers can use the same project but ideally we want separate project for Production vs QA/STG

1 Answer 1

18

If you really need a single APK that somehow self-selects which Firebase project it works against, you can't use the automatic init provided by the Gradle plugin.

Normally, Firebase apps init automatically (definitely read my blog post there) via data injected by the gradle plugin. This system works in a vast majority of cases, but not in yours.

If the normal case doesn't work for you, you'll have to disable the FirebaseInitProvider via Android build tools (see tools:node="remove"), and initialize your app yourself with FirebaseApp.initializeApp() with a FirebaseOptions that you construct. You need to arrange for the init to happen before any APIs are called, or you'll get errors.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply and it did help us in solving the problem. I just had one question before I mark this answer as accepted. We added tools:node="remove" in FirebaseInitProvider and along with it we also removed the google-services.json file from the project and removed the "apply plugin: 'com.google.gms.google-services'" from the build.gradle file. This way we ensured that the automatic initialization never happens (not even by mistake). This should be okay, right? I was able to receive test notifications from console. Do you see any downside or impact of doing this?
Removing the plugin, the google-services.json file, and the FirebaseInitProvider (via tools:node="remove") definitely all go together as a package. Your project should be good to go if you successfully initialized on your own!
I'm still getting "Missing google_app_id. Firebase Analytics disabled" message. What else could I try?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.