0
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 quite the 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}"
}
kingston
  • 11,053
  • 14
  • 62
  • 116
Ashok Varma
  • 3,489
  • 3
  • 28
  • 43

1 Answers1

15

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.

Ian Barber
  • 19,765
  • 3
  • 58
  • 58
  • Where can I learn more about `background_crash`? It appears in an [ANR I am seeing](http://stackoverflow.com/questions/37357974/after-upgrading-to-google-play-services-9-0-0-app-hangs-in-dynamitemodulesc) after upgrading to Google Play Services 9.0.0. – Bob Snyder May 22 '16 at 16:36
  • 2
    Yes i am calling that from Application Subclass. Because i need some remoteConfig values in my application initialisation. Is there any other way to do this? and also what if Firebase Initialization didn't happened even in the first activity ?? – Ashok Varma May 22 '16 at 16:39
  • 1
    The initialisation will happen fine for the app subclass - the issue is it only happens for the main process and not the background_crash process. The check I suggested effectively means you init code only runs on the main process, not the background one. – Ian Barber May 22 '16 at 20:58
  • @IanBarber the solution worked. But is there anyother way to do this. – Ashok Varma May 24 '16 at 17:12