Application crashing on some devices because "Default FirebaseApp is not initialized in this process"

991 views Asked by At

I am using Firebase Crash Reporting and Firebase Remote Config. Version of both is 9.8.0.

On most devices setup works perfectly (I followed Set up crash reporting). But on small percentage of devices (it is actually crash with the highest occurrence) it crashes when I try to initialize Remote Config in Application onCreate method.

java.lang.RuntimeException: Unable to create application com.company.application.AppApplication: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.company.application. Make sure to call FirebaseApp.initializeApp(Context) first.
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6429)
    at android.app.ActivityThread.access$1800(ActivityThread.java:229)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:7329)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.company.application. Make sure to call FirebaseApp.initializeApp(Context) first.
    at com.google.firebase.a.d(Unknown Source)
    at com.google.firebase.b.a.a(Unknown Source)
    at com.company.application.d.a.a(SourceFile:21)
    at com.company.application.AppApplication.onCreate(SourceFile:76)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1037)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6426)
    ... 8 more
2

There are 2 answers

4
Bob Snyder On BEST ANSWER

Prior to version 10.0.0, Firebase Crash created an additional process in your app named background_crash. An instance of your AppApplication class is created and executed for each process in your app, including background_crash.

If you want to perform initialization of Firebase services in your application class, you need to add a guard to prevent the initialization from being performed in background_crash. On way to do that is:

    if (!FirebaseApp.getApps(this).isEmpty()) {
        // Not in crash process.  Do your Remote Config init here.
    }

Another solution is to upgrade to the latest version of Firebase, 10.0.1.

Assuming this answer is valid, I can't explain why the failure only occurs on some devices, unless the version of Google Play Services installed on the device is a factor, and the failing devices have an older version.

0
Vishal  Verma On
  1. set classpath 'com.google.gms:google-services:4.0.1' in dependencies.
  2. Implement the androidTestImplementation dependencies :

    androidTestImplementation('com.android.support.test.espresso:espresso-core:.2.2',
    

    { exclude group: 'com.android.support', module: 'support-annotations' })