I initialize my FirebaseApp using
val prodFirebaseOptions: FirebaseOptions = FirebaseOptions.Builder()
.setApplicationId(context.getString(R.string.prod_google_app_id)) // Required for Analytics.
.setApiKey(context.getString(R.string.prod_google_api_key)) // Required for Auth.
.setDatabaseUrl(context.getString(R.string.prod_firebase_database_url)) // Required for RTDB.
.setGcmSenderId(context.getString(R.string.prod_gcm_defaultSenderId))
.setProjectId(context.getString(R.string.prod_project_id))
.setStorageBucket(context.getString(R.string.prod_storage_bucket))
.build()
FirebaseApp.initializeApp(context, prodFirebaseOptions, "production")
val firebaseApp = FirebaseApp.getInstance("production")
And then to initialize all the services I use:
val firestore = FirebaseFirestore.getInstance(firebaseApp)
val auth = FirebaseAuth.getInstance(firebaseApp)
val storage = FirebaseStorage.getInstance(firebaseApp)
When I want to initialize my FirebaseMessaging and FirebaseAnalytics, there is not getInstance
method that accepts a FirebaseApp
:
val messaging = FirebaseMessaging.getInstance() // will use "default" app instead of providing
val analytics = FirebaseAnalytics.getInstance() // will use "default" app instead of providing
In addition to that, there is no way to initialize the FirebaseMessagingService
with the non-default app.
Is there a solution to this problem? Can I somewhat change the default app maybe?
Versions:
com.google.firebase:firebase-messaging:20.1.0
com.google.firebase:firebase-analytics:17.2.1
com.google.firebase:firebase-core:17.2.1