1

这是我在尝试使用 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 依赖项,则不会发生崩溃。

4

1 回答 1

2

FirebaseApp with name [DEFAULT] doesn't exist当您在由 Firebase 崩溃报告创建的单独进程上运行 Firebase 代码时,会导致您的自定义Application类是为应用中的每个进程创建的。

您应该将代码从您的Application班级移动到其他地方。这可能在您的主要活动中(始终在您的主流程中),也可能在您在清单中注册onCreate()的单独活动中(就像在应用程序流程的生命周期中运行一次,但仅运行在一个过程中)。ContentProviderContentProvideronCreate()Application.onCreate()

于 2016-07-14T04:17:15.980 回答