DariusL DariusL - 1 month ago 4x
Android Question

Leakcanary crashes with Google's Firebase

When processing a leak, I get a

java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
inside my
. From what I understand, this happens because LeakCanary creates my application class without all the Google Play Services stuff and Firebase cannot initialize successfully. Any ideas how to fix this?

I'm using
and this happens after dumping the heap.


I believe I found a workaround. Instead of using the Google Play Services plugin and google-services.json you can configure and initialize Firebase yourself in Application.onCreate or wherever.

protected FirebaseApp proviceFirebaseApp(Application application) {
    FirebaseOptions options = new FirebaseOptions.Builder()
    return FirebaseApp.initializeApp(application, options);

Finding the keys was a bit of a mystery. Inside google-services.json you'll need the database url, which is project_info.firebase_url. If you have more than one application using the Firebase repo, there will be multiple client objects here.

If you're using Google Sign In, the oauth id is inside client[app].oauth_client[1].client_id. You can figure out your client according to the package name and the oauth_client was the second object that looked like this:

  "client_id": "asfagasdgdas",
  "client_type": 3

The api key is client[app].api_key, again find the client based on your package.

Forgive the pseudo-json.

The structure might change later, this was written for Play Services version 9.0.1.