Ashok Varma Ashok Varma - 4 months ago 234
Android Question

New Firebase Initialize Crashes

FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();


When i call this the app crashes the error log says FirebaseApp doesn't exist.

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.remoteconfig.FirebaseRemoteConfig.getInstance(Unknown Source)


So i tried to initialised FireBase Myself. so, new code looks like

FirebaseApp.initializeApp(this, FirebaseOptions.fromResource(this));
FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();


The new issue is Quit opposite. Check the crash Log it says that FirebaseApp already exists

Caused by: java.lang.IllegalStateException: FirebaseApp name [DEFAULT] already exists!
at com.google.android.gms.common.internal.zzaa.zza(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)


Did my Firebase App initialised/ should i initialise it ?? Because in both cases my app crashes and even crash reports are not working. Here is the crash report error

E/FirebaseCrashSenderServiceImpl: Error sending crash report
ait: Server did not receive report: Origin Error message: Mobile Crash and Performance Reporting API has not been used in project project-546786591250077938 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/mobilecrashreporting.googleapis.com/overview?project=project-XXXXXXXXXX then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
at com.google.firebase.crash.internal.service.FirebaseCrashSenderServiceImpl.a(:com.google.android.gms.DynamiteModulesC:299)
at com.google.firebase.crash.internal.service.FirebaseCrashSenderServiceImpl.a(:com.google.android.gms.DynamiteModulesC:146)
at com.google.firebase.crash.internal.service.FirebaseCrashSenderServiceImpl.onHandleIntent(:com.google.android.gms.DynamiteModulesC:108)
at aid.onTransact(:com.google.android.gms.DynamiteModulesC:69)
at android.os.Binder.transact(Binder.java:387)
at com.google.firebase.crash.internal.zzf$zza$zza.zzI(Unknown Source)
at com.google.firebase.crash.internal.service.FirebaseCrashSenderService.onHandleIntent(Unknown Source)


My build.gradle

ext {
firebaseVersion = "9.0.0"
}
dependencies {
compile "com.google.firebase:firebase-core:${firebaseVersion}"
compile "com.google.firebase:firebase-ads:${firebaseVersion}"
compile "com.google.firebase:firebase-crash:${firebaseVersion}"
compile "com.google.firebase:firebase-config:${firebaseVersion}"
}

Answer

Are you calling FirebaseRemoteConfig in an Application subclass? You may be hitting the issue where the background_crash also instantiates an app subclass, and therefore executes your code on a process where the FirebaseApp isn't set up. If you look at the full stack trace you should be able to see what process it occurred on near the top.

FirebaseApp is normally configured by a ContentProvider automatically merged in to your manifest by the Firebase SDK. Initializing Firebase Remote Config causes it to try and read from its local cache, which involves getting the app ID value from FirebaseApp. If you want to guard against uninitialized errors, then you can either move your code to an Activity, or check whether you have a FirebaseApp instance before calling the RemoteConfig code in your Application subclass:

@Override
public void onCreate() {
  super.onCreate();
  if (!FirebaseApp.getApps(this).isEmpty()) {
    FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();

  }
}

If its not that, check you aren't getting any errors from the google-services plugin at build time.

Comments