others-how to manually initialize firebase in android app or how to diable the automatic initialization of firebase?

1. Purpose

In this post, I will show you how to manually initialize firebase in android app.



2. Solution

2.1 First, add firebase dependency

implementation platform('com.google.firebase:firebase-bom:30.1.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-crashlytics'



2.2 Second, disable auto start of firebase

Add this to your android_manifest.xml

<!-- Disable firebase auto initialization -->
<provider
    android:name="com.google.firebase.provider.FirebaseInitProvider"
    android:authorities="${applicationId}.firebaseinitprovider"
    android:exported="false"
    tools:node="remove"/>

It means to remove the firebaseinitprovider node that initialize firebase in your android manifest.

2.3 Third, initialize firebase manually

FirebaseApp.initializeApp(this);

It works!

3. More information

3.1 More about the firebase auto initialization

More about FirebaseApp.initializeApp(this):

This method is called at app startup time by . Call this method before any Firebase APIs in components outside >the main process.

The FirebaseOptions values used by the default app instance are read from string resources.

open static fun initializeApp(context: Context!, options: FirebaseOptions!): FirebaseApp! Initializes the default FirebaseApp instance. Same as initializeApp(Context, * FirebaseOptions, String), but it >uses DEFAULT_APP_NAME as name.

It’s only required to call this to initialize Firebase if it’s not possible to do so automatically in >com.google.firebase.provider.FirebaseInitProvider. Automatic initialization that way is the expected situation.

open static fun initializeApp(context: Context!, options: FirebaseOptions!, name: String!): FirebaseApp! A factory method to initialize a FirebaseApp.



3. Summary

In this post, I demonstrated how to manually initialize firebase in android app. That’s it, thanks for your reading.