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