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

Android Firebase崩溃报告:名为[DEFAULT]的FirebaseApp不';不存在,android,firebase,firebase-authentication,firebase-crash-reporting,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和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崩溃依赖项,则不会发生崩溃。

名为[默认值]的firebase应用程序不存在。
是在firebase崩溃报告为应用程序中的每个进程创建自定义
应用程序时,在单独的进程上运行firebase代码造成的


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

这是初始化代码与Firebase中某些自动初始化代码之间的竞争条件。您可能希望将初始化移到主活动(稍后运行)中,或者最好移到内容提供商(较早运行)中。谢谢您的回答。我把代码放在主要活动中的一个问题是,我的主要活动不能保证每次都启动。例如,如果我从共享目的启动,我不会打开我的主要活动。所以我可以有重复的代码或一个基本活动,两者都不是。内容提供商似乎有点奇怪,因为Im实际上不会提供任何内容。也许注射是一种方式?是的,完全同意ContentProvider方法的奇怪感觉。您完全可以将代码作为静态方法放在一个类中,并从需要确保其就绪的每个组件调用它-如果您已经完成了设置,则静态布尔值将确保每个进程初始化只执行一次。好的,也许这是最好的方法。谢谢另一方面,是否真的有必要在单独的过程中运行Firebase崩溃报告?@Modge-这是当前版本的一项要求,尽管我似乎记得在网上看到他们希望删除该要求。