Eoin
Eoin

Reputation: 4066

Firebase Crash Reporting : FirebaseApp with name [DEFAULT] doesn't exist

This an exception I encountered when trying to use FirebaseAuth and Firebase Crash Reporting. I am trying to sign in anonymously in my application onCreate

public class MainApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
        firebaseAuth.signInAnonymously().addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                Log.wtf("TAG", "Signed signInAnonymously successful ");
            }
        });
    }
}

I also want to use crash reporting so my gradle dependencies looks like this.

dependencies {
    // other dependencies
    // ...

    compile 'com.google.firebase:firebase-core:9.2.1'
    compile 'com.google.firebase:firebase-storage:9.2.1'
    compile 'com.google.firebase:firebase-auth:9.2.1'
    compile 'com.google.firebase:firebase-config:9.2.1'
    compile 'com.google.firebase:firebase-crash:9.2.1'
}

apply plugin: 'com.google.gms.google-services'

After a certain amount of time I will get a crash dialog and this exception. Its another process that crashes so the app itself will still run.

java.lang.RuntimeException: Unable to create application com.android.tools.fd.runtime.BootstrapApplication: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4612)
    at android.app.ActivityThread.access$1600(ActivityThread.java:169)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5476)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. 
    at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
    at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
    at com.redstar.collectors.MainApplication.onCreate(MainApplication.java:22)
    at com.android.tools.fd.runtime.BootstrapApplication.onCreate(BootstrapApplication.java:369)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4609)
    at android.app.ActivityThread.access$1600(ActivityThread.java:169) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:136) 
    at android.app.ActivityThread.main(ActivityThread.java:5476) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
    at dalvik.system.NativeStart.main(Native Method)

If I remove the firebase-crash dependency there will be no crash.

Upvotes: 1

Views: 1926

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199825

FirebaseApp with name [DEFAULT] doesn't exist is caused when you run Firebase code on the separate process that is created by Firebase Crash Reporting as your custom Application class is created for each process in your app.

You should move code from your Application class to somewhere else. This could be in your main activity (which would always be in your main process) or could be in the onCreate() of a separate ContentProvider you register in your Manifest (a ContentProvider's onCreate() is run once in the lifecycle of your app's process just like Application.onCreate(), but only runs in a single process).

Upvotes: 2

Related Questions