Skip to content

Enable FCM when Firebase project is dinamically initialised #4068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
axionnneeeel opened this issue Sep 8, 2022 · 6 comments
Closed

Enable FCM when Firebase project is dinamically initialised #4068

axionnneeeel opened this issue Sep 8, 2022 · 6 comments

Comments

@axionnneeeel
Copy link

I am initializing Firebase dynamically with FirebaseApp.initializeApp(Builder) with all the project attributes set(including gcmSenderId), so I have no google services JSON in the project root as I'm choosing the firebase project at login. Everything works fine(auth sdk, firestore sdk, storage sdk etc.) apart from FCM. I'm getting the token successfully through onNewToken() method and then trying to send a test push to the token. I'm not getting the test push.

I've tried to set "firebase_messaging_auto_init_enabled" and "firebase_analytics_collection_enabled" to false and then after initializeApp to call FirebaseMessaging.getInstance().setAutoInitEnabled(true); but still doesn't work.

I can see in the logs that "Missing google_app_id. Firebase Analytics disabled. See ..." error is thrown so this may be the reason it's not working, but can't figure out why as google services json is missing intentionally and everything is fine after dynamically setting up Firebase.

@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@argzdev
Copy link
Contributor

argzdev commented Sep 8, 2022

Hi @axionnneeeel, thanks for reporting. Could you share a few details below:

  1. Firebase Cloud Messaging version
  2. Code snippet in relation to:

trying to send a test push to the token

  1. Stacktrace of your error
  2. Is the issue consistently reproducible?

With these information, I'll try to reproduce this on my end. If there's any chance you could share a minimal reproducible example, that'll greatly help us investigating this. Thanks!

@axionnneeeel
Copy link
Author

axionnneeeel commented Sep 8, 2022

Hi @argzdev

  1. com.google.firebase:firebase-messaging-ktx:23.0.8
  2. I'm trying to send push to the token using the Firebase console -> Cloud Messaging -> Send your first message -> Add notification title and text -> Send test message -> Add registered token -> Test
  3. No other logs apart from "Missing google_app_id. Firebase Analytics disabled. See ..." after initializeApp, so probably the push notification doesn't arrive at all.
  4. Yes, doesn't work at all.

Some other info for a reproducible example:

a. No google services JSON
b. Create a Builder like:

FirebaseOptions firebaseOptions = new FirebaseOptions.Builder()
            .setApplicationId("xxx")
            .setApiKey("xxx")
            .setDatabaseUrl("xxx")
            .setProjectId("xxx")
            .setStorageBucket("xxx")
            .setGcmSenderId("x").build()

c. Initialize app like FirebaseApp.initializeApp(context, firebaseOptions);
d. Run the app and get your push notif token from onNewToken() method or FirebaseMessaging.getInstance().getToken() callback.
e. Try to send a test push as described at point 2. above

The result: Push doesn't arrive
The expected result: Push should arrive

Thanks

@argzdev
Copy link
Contributor

argzdev commented Sep 12, 2022

Just to give some insights, the error you're receiving Missing google_app_id. Firebase Analytics disabled is due to #66 - Firebase Analytics does not work when using FirebaseOptions. That said, this should not affect your FCM setup.

Thanks for the code snippet, I tried creating a clean minimal project with your setup, however, I'm still able to receive the push notification. I also didn't set firebase_messaging_auto_init_enabled or firebase_analytics_collection_enabled. It's possible that there are incorrect details you've provided in your FirebaseOptions.

Could you try the troubleshooting steps in our documentation? Let me know if it helps. Thanks!

@axionnneeeel
Copy link
Author

I tried the other way to test push notifs from the same menu like "Cloud Messaging -> Send your first message -> Add notification title and text -> Next -> Set as target my app -> Next -> Next -> Review -> Publish" and it's working that way. Any idea on why the "Send test message" way didn't work?

@argzdev
Copy link
Contributor

argzdev commented Sep 14, 2022

Hi @axionnneeeel, if it works with a regular campaign, then there's no issue with your dynamic setup. However, it's possible that you're sending the test message to a different FCM registration token. You could also try testing on a physical device. I noticed that there are times where an emulator receives the notification late or not at all.

If this still doesn't work, maybe you could take a look at our quickstart samples, you can also use it as a reference and compare the setup with your project.

@firebase firebase locked and limited conversation to collaborators Oct 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants