java.lang.IllegalStateException:名称为[DEFAULT]的FirebaseApp [英] java.lang.IllegalStateException: FirebaseApp with name [DEFAULT]
问题描述
导致:java.lang.IllegalStateException:名称为[DEFAULT]的FirebaseApp不存在。
您是否使用Firebase崩溃报告?你可能会遇到这个错误,因为如果它击中后台进程而不是主要的。
崩溃报告会创建第二个进程( background_crash
)来发送崩溃。不幸的是,Android应用程序中的所有进程共享一个共同的 Application
子类,所以您的 onCreate
方法在后台进程中运行以及。这试图初始化数据库,失败。
解决方法是确保只有在Firebase正确配置(将在主进程中)时才会运行数据库调用。你可以这样检查:
@Override
public void onCreate(){
super.onCreate );
if(!FirebaseApp.getApps(this).isEmpty()){
FirebaseDatabase.getInstance()。setPersistenceEnabled(true);
}
}
I have been getting this issue.. followed the upgrade guide for new firebase sdk...saved the google services json file in app directory.. still the same error as you but for the database...
Caused by: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
Are you using Firebase Crash Reporting? You might be hitting this error because of that if its hitting a background process and not the main.
Crash Reporting creates a second process (background_crash
) to send crashes. Unfortunately, all processes in an Android app share a common Application
subclass, so your onCreate
method is run in the background process as well. That tries to initialise database, which fails.
The fix is to make sure the Database call is only run when Firebase is properly configured (which will be in the main process). You can check like this:
@Override
public void onCreate() {
super.onCreate();
if (!FirebaseApp.getApps(this).isEmpty()) {
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
}
}
这篇关于java.lang.IllegalStateException:名称为[DEFAULT]的FirebaseApp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!