java.lang.IllegalStateException: FirebaseApp with name [DEFAULT]

前端 未结 3 1609
抹茶落季
抹茶落季 2020-12-10 11:24

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

3条回答
  •  眼角桃花
    2020-12-10 12:03

    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);
      }
    }
    

提交回复
热议问题