2

I'm trying integrate Firebase Cloud Messaging, specifically for android push notifications, into a my own library module so I can easily implement this into any app without having to touch Firebase. I have successfully integrated it initializing the Firebase Messaging SDK dynamically inside my library by using FirebaseOptions.Builder as well it generated a push token.

BTW I am initializing FirebaseApp in my library and calling it in the app MainActivity.java

But whenever I test sending my own push notification while the app is in the foreground I get

Default FirebaseApp is not initialized in this process. Make sure to call FirebaseApp.initializeApp(Context)

From the Error Output it seems to be calling FirebaseApp instance in the MessagingAnalytics class to log performance before it calls onMessageRecieved.

As well no notification shows up on the phone when sending a Notification while the app is in the background.

I want my library module to handle everything to do with Push Notifications, I have also created a MyMessagingService in the library module and added the appropriate Service in the manifest of the library module.

If anyone has done this before with FCM in a library or knows how to fix these crashes please let me know.

EDIT

I am building the FirebaseApp manually without google-service.json inside the module. Like this:

FirebaseApp.initializeApp(context, new FirebaseOptions.Builder().setApplicationId(applicationID).setApiKey(apiKey).setGcmSenderId(senderID).setProjectId(projectID).build());
Ethrodom
  • 67
  • 7
  • did you put the google-services.json in your module and add dependencies on the module? – Abdullah Z Khan Nov 01 '21 at 06:46
  • @AbdullahZKhan I added Firebase Messaging dependencies on the module. But I am building the FirebaseApp manually without the google-services.json so i can build the FirebaseApp in the module rather in the actual app, `FirebaseApp.initializeApp(context, new FirebaseOptions.Builder().setApplicationId(applicationID).setApiKey(apiKey).setGcmSenderId(senderID).setProjectId(projectID).build());` – Ethrodom Nov 01 '21 at 23:06
  • Where in the module do you initialize the app? FCM being in the background, I think you have to initialize in the Application class or provide a library method to do so. – Abdullah Z Khan Nov 02 '21 at 04:02
  • I am Initializing the app by calling a method in the module library from MainActivity OnCreate. Its initializing fine when the app starts but when a Push Notification is received it crashes and give me the UnInitialized app error. I think its because the FirebaseMessagingService is trying to initialize the app with google-services.json in the background but cannot find it. – Ethrodom Nov 02 '21 at 05:53
  • ? Hello, Firebase Push Notifications are app-specific so you should initialize FirebaseApp on the app module and you must have the google-service.json file. You can put the firebase dependencies inside the module library gradle using the "api" declaration, but the FirebaseApp must be initialized inside the app module and also the "FirebaseMessagingService" must be in the app module instead of the library module. I tryed this years ago and for what I remember this was the only solution I found. – Davide Sep 30 '22 at 10:05

0 Answers0