Firebase崩溃报告:名称为[DEFAULT]的FirebaseApp不存在

时间:2016-07-14 03:59:21

标签: android firebase firebase-authentication firebase-crash-reporting

这是我在尝试使用FirebaseAuth和Firebase崩溃报告时遇到的异常。我正试着在我的申请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 ");
            }
        });
    }
}

我还想使用崩溃报告,因此我的gradle依赖项看起来像这样。

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'

经过一段时间后,我会得到一个崩溃对话框和这个例外。它的另一个进程崩溃,所以应用程序本身仍将运行。

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)

如果我删除了firebase-crash依赖项,那么就不会崩溃。

1 个答案:

答案 0 :(得分:2)

当您为应用中的每个流程创建自定义function findAllMinimum(scores) { var minScore = _.min(_.values(scores)); return _.filter(_.keys(scores), function (key) { return scores[key] === minScore; }); } 类时,在Firebase崩溃报告创建的单独流程上运行Firebase代码时,会导致

FirebaseApp with name [DEFAULT] doesn't exist

您应该将代码从Application类移到其他地方。这可以在您的主要活动中(始终在您的主要流程中),也可以在您在Manifest中注册的Application onCreate() ContentProvider ContentProvider { {1}}在应用程序流程的生命周期中运行一次,就像onCreate()一样,但只能在一个进程中运行。