java.lang.IllegalStateException:名称为[DEFAULT]的FirebaseApp [英] java.lang.IllegalStateException: FirebaseApp with name [DEFAULT]

查看:123
本文介绍了java.lang.IllegalStateException:名称为[DEFAULT]的FirebaseApp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到这个问题..跟着新的firebase sdk的升级指南...保存在应用程序目录中的google服务json文件..仍然是相同的错误,但你的数据库...

 导致: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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆