"java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist", but only on SOME devices

12,004 views
Skip to first unread message

b0b

unread,
May 30, 2016, 11:01:40 AM5/30/16
to Firebase Google Group
I just added Firebase to a large Android application which is now only published to beta.

I'm not using Firebase Crash reporting, just remote configs, messaging and ads.

Although the app runs fine for most beta users I got a few automated crash reports (using ACRA, not Firebase) with the dreaded:

java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist

This IllegalStateException happens the first time a Firebase API call is made in an Activity, for example:

FirebaseRemoteConfig.getInstance().getBoolean("someparam");

But it could be any Firebase API call that needs a FirebaseApp.

Googling around, the only info I found of this happening is for people either that did not apply the com.google.gms.google-services gradle
plugin properly (in which case it would always crash), or made a Firebase API call in an overridden Application class with Firebase crash enabled (not my case).

I'm at at loss to understand why this IllegalStateException happens for some users.
There doesn't seem to be a pattern in the devices / Android versions it happened:

- an Asus running Android 5.0 (has greenify installed, not rooted)
- a LG running 5.1.1 (rooted)
- an Acer running 5.1.1 (rooted, running Xposed)
- a Samsung running 6.0.1 
- a Nexus 6 running 6.0.1 (rooted, running Xposed)

Again, there is no issue for most users. Only a few

A few supposition on what happens:

- the Firebase Content Provider that handle all initialization does not run at all before the Application's onCreate(), for whatever reason
- or it runs but with an error, leaving Firebase uninitialized

Right now, I have no idea how to fix this. The only thing I can think of is to wrap Firebase API calls to check if there is a FirebaseApp:

if (!FirebaseApp.getApps(this).isEmpty()) {
   // do some Firebase API call
}

Doug Stevenson

unread,
May 30, 2016, 5:13:18 PM5/30/16
to Firebase Google Group
Do you have any components in your app that run in another process?  You can tell because they'll have an attribute called "android:process" somewhere in the manifest entry.

When one of these non-main process components gets created, the process that hosts it will have its Application object instantiated, but none of the ContentProviders.  ContentProviders are only created for the main process, which means the automatic Firebase init only happens in that main process.  So using a Firebase API in a non-main process could have the problem that appears to fail without previous init.

Doug

b0b

unread,
May 30, 2016, 6:24:04 PM5/30/16
to Firebase Google Group
I have no separate processes for my app. I can see in the crash reports that the app is started normally via the standard launch Intent.
Anyway, since my uses of the Firebase API is not mandatory, I have safeguarded all calls, verifying if a FirebaseApp exists first.

b0b

unread,
May 31, 2016, 9:50:46 AM5/31/16
to Firebase Google Group
More on this.

After making a new beta version on my app, it seems this IllegalStateException can possibly happen only if making Firebase API call in an overridden Application's onCreate(), which my application was doing (to initialize remote config).
Since I moved this call to an Activity, there is no more crash reports.
It is still unclear why it crashed in the first place, since I'm not using multi-process and not using Firebase crash reporting.

tl;dr: avoid making Firebase API calls in the Application class even if not using crash reporting.

Doug Stevenson

unread,
May 31, 2016, 12:47:02 PM5/31/16
to Firebase Google Group
I believe, in general, doing things in an Application.onCreate is a supported situation.  Firebase is initialized automatically in a ContentProvider.onCreate, which is executed before Application.onCreate.  I know some of our early access partners are using Firebase in Application, and I haven't had a problem with it myself.  The only known problems are when crash reporting or multiple processes are in play.

Could you show the code your trying to run along with a stack trace?  Stack Overflow is a good place to put this sort of thing since it might help other people searching there.

Doug

b0b

unread,
May 31, 2016, 1:21:00 PM5/31/16
to Firebase Google Group
Looks like my supposition on this issue happening only in Application onCreate() is wrong

This afternoon I published an app update.
To track this issue, the app sends a silent crash report if there is no FirebaseApp initialized (eg if FirebaseApp.getApps(App.getInstance()).isEmpty() == true).
In that situation is detected, all Firebase functions are disabled (remote configs and analytics).

I already got a few of these silent reports on several devices.

The additional logging traces I have show that on these devices, writing to the external storage (that is, in subfolders of Environment.getExternalStorageDirectory()) 
is not working (fails, if say you attempt to create a file or directory). I believe this can happen if that storage is mounted via USB. I already seen happen randomly
on some of my test devices after a while, without explanation and fixed by a reboot.

Does the initialization of Firebase expects external storage to be writable ?

Doug Stevenson

unread,
Jun 1, 2016, 1:28:03 AM6/1/16
to fireba...@googlegroups.com
I don't suspect that Firebase makes a direct attempt to use external storage at all just for init.  Some components will definitely use internal, private storage of the app.  For your test app, check the contents of the external storage root under Android/data/your.package.name.  My firebase test app doesn't even have a folder there created for it because it's never attempted to write anything externally.

I suppose it's possible for Firebase to implicitly access external storage on init if the app was installed on external storage rather than internal.  But in that case I suspect the app wouldn't even launch if external storage was unmounted.

If you have some stack traces or something to work with that would help a lot.

Doug


--
You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/ZIhO6Wwe1oM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/a896b128-446c-4aba-8e58-b6a6c3706ba5%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

b0b

unread,
Jun 1, 2016, 10:59:21 AM6/1/16
to Firebase Google Group
Here's the logcat output of my app that I get whenever I get a silent report when there is no FirebaseApp.
All logs look identical accross various devices and Android version for this issue.

main (1) ] INFO - 09:59:59.46 - q : logging to file is not enabled
1   [main (1) ] INFO - 09:59:59.49 - f : API level: 23
2   [main (1) ] INFO - 09:59:59.49 - f : manufacturer: samsung
3   [main (1) ] INFO - 09:59:59.49 - f : device: SM-T810
4   [main (1) ] INFO - 09:59:59.49 - f : app version: 2.7
5   [main (1) ] INFO - 09:59:59.49 - f : app external dir: Android/data/<redacted package>
6   [main (1) ] INFO - 09:59:59.49 - f : xposed running: false
7   [main (1) ] INFO - 09:59:59.49 - f : memory class: 192
8   [main (1) ] INFO - 09:59:59.49 - f : large memory class: 512
9   [main (1) ] INFO - 09:59:59.49 - f : debuggable: false
10  [main (1) ] INFO - 09:59:59.50 - e : first app run
11  [main (1) ] INFO - 09:59:59.55 - e : first app version run
12  [main (1) ] INFO - 09:59:59.56 - f : failed to create directory /storage/emulated/0/Android/data/<redacted package>/cache/images
13  [main (1) ] INFO - 09:59:59.58 - am : watchdog: set inactivity delay to 15 mins
14  [main (1) ] INFO - 09:59:59.58 - f : failed to create directory /storage/emulated/0/<redacted name>/cache/media
15  [main (1) ] INFO - 09:59:59.59 - alRendererPrefsActivity : getLocalRendererRemoteControlVideoApp: no package name
16  [main (1) ] INFO - 09:59:59.60 - alRendererPrefsActivity : remote video player: MX Player Pro
17  [main (1) ] INFO - 09:59:59.61 - f : failed to create directory /storage/emulated/0/<redacted name>/tmp
18  [main (1) ] INFO - 09:59:59.61 - f : failed to create directory /storage/emulated/0/<redacted name>/subtitles
19  [main (1) ] INFO - 09:59:59.62 - f : failed to create directory /storage/emulated/0/<redacted name>/booklets
20  [main (1) ] INFO - 09:59:59.62 - z : Successfully hacked permanent menu key
21  [main (1) ] INFO - 09:59:59.65 - MainActivity : onCreate
22  [main (1) ] INFO - 09:59:59.65 - n : screen generalized size: xlarge
23  [main (1) ] INFO - 09:59:59.65 - n : screen generalized density: 320 dpi
24  [main (1) ] INFO - 09:59:59.65 - n : logical density factor: 2.000000
25  [main (1) ] INFO - 09:59:59.65 - n : screen size (pixels): 1536x2048
26  [main (1) ] INFO - 09:59:59.65 - n : screen size (inches): 5.787404x7.755930, diagonal: 9.677216
27  [main (1) ] INFO - 09:59:59.65 - n : xdpi: 265.403992
28  [main (1) ] INFO - 09:59:59.65 - n : ydpi: 264.056000
29  [main (1) ] INFO - 09:59:59.65 - n : landscape: false
30  [main (1) ] INFO - 09:59:59.65 - n : isPhoneSize: false
31  [main (1) ] INFO - 09:59:59.65 - n : smallest width (dp): 768
32  [main (1) ] SEVERE - 09:59:59.65 - f : java.lang.Exception: no Firebase app
33  [main (1) ] SEVERE - 09:59:59.65 - f : java.lang.Exception: no Firebase app
34  at <redacted package>.f.a(SourceFile:184)
35  at <redacted package>.MainActivity.onCreate(SourceFile:40)
36  at android.app.Activity.performCreate(Activity.java:6877)
37  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
38  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3209)
39  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3352)
40  at android.app.ActivityThread.access$1100(ActivityThread.java:223)
41  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1797)
42  at android.os.Handler.dispatchMessage(Handler.java:102)
43  at android.os.Looper.loop(Looper.java:158)
44  at android.app.ActivityThread.main(ActivityThread.java:7231)
45  at java.lang.reflect.Method.invoke(Native Method)
46  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
47  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
... execution of app continues normally with Firebase disabled

The source code at this line 'at <redacted package>.f.a(SourceFile:184)' is simply:

            if(FirebaseApp.getApps(App.getInstance()).isEmpty())   // App.getInstance() is just the Application Context
                App.acraReportSilentException(new Exception("no Firebase app"));    // line 184
            }

The log shows that this situation happens only in the following conditions:

- only if it is the first time ever the app is run, after a fresh install. "first app run" in traces above tell us that.
It never happens on subsequent launches because I never saw a log without "first app run".
- External storage is not writable (which is unusual), as the "failed to create directory" traces tell us

This really look like a corner case. I could workaround it cheking that FirebaseApp is initialized correctly so it is no a huge problem (and it only happens
on first app run) but it would still be interesting to understand why it happens as I cannot think it only happens in my app.

Austyn Mahoney

unread,
Jun 6, 2016, 6:22:33 PM6/6/16
to Firebase Google Group
I think I am getting the same error message on my Google APIs API level 23 emulator. My build.gradle is setup as the quick start guide suggests. I am using firebase-crash v9.0.2.

Here are the logs from the crash. It doesn't actually log a stacktrace.

E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.android.gms.crash.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.<redacted package>-2/base.apk"],nativeLibraryDirectories=[/data/app/com.<redacted package>-2/lib/x86_64, /vendor/lib64, /system/lib64]]
W/System: ClassLoader referenced unknown path: /system/priv-app/PrebuiltGmsCore/lib/x86_64
D/ChimeraCfgMgr: Reading stored module config
I/DynamiteModule: Considering local module com.google.android.gms.crash:0 and remote module com.google.android.gms.crash:2
I/DynamiteModule: Selected remote version of com.google.android.gms.crash, version >= 2
W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000002/n/x86_64
D/ChimeraFileApk: Primary ABI of requesting process is x86_64
D/ChimeraFileApk: Classloading successful. Optimized code found.
I/FirebaseCrashReceiverServiceImpl: FirebaseCrashReceiverServiceImpl created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/user/0/com.google.android.gms/app_chimera/m/00000002/DynamiteModulesC_GmsCore_prodmnc_alldpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000002/n/x86_64, /vendor/lib64, /system/lib64]]]
D/FirebaseCrashReceiverServiceImpl: onCreate
I/DynamiteModule: Considering local module com.google.android.gms.flags:0 and remote module com.google.android.gms.flags:1
I/DynamiteModule: Selected remote version of com.google.android.gms.flags, version >= 1
I/FirebaseCrashSenderServiceImpl: FirebaseCrashSenderServiceImpl created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/user/0/com.google.android.gms/app_chimera/m/00000002/DynamiteModulesC_GmsCore_prodmnc_alldpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000002/n/x86_64, /vendor/lib64, /system/lib64]]]
D/FirebaseCrashSenderServiceImpl: onCreate
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 1
E/FA: Task exception on worker thread: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. : com.google.android.gms.measurement.internal.zzt.zzEd(Unknown Source)

Doug Stevenson

unread,
Jun 7, 2016, 11:24:41 AM6/7/16
to Firebase Google Group
Austyn, could you double check that this error is happening with the 9.0.2 client library?  Some engineers here suspect that this error would only happen on older versions.

Doug

Sankha Palihawadana

unread,
Jun 13, 2016, 11:58:47 AM6/13/16
to Firebase Google Group
I am getting this exact same error and I am on 9.0.2. Also this error appeared first when I started using google play services (after adding 'compile 'com.google.android.gms:play-services:9.0.2'')

Eugene Garastovych

unread,
Jul 4, 2016, 11:15:31 AM7/4/16
to Firebase Google Group

I am having the same issue when attempting to get a Firebase instance in Application's onCreate.
Here are the libraries I am using:
compile 'com.google.firebase:firebase-database:9.0.2'
compile 'com.google.firebase:firebase-auth:9.0.2'
gms added to classpath in project's build.gradle:
classpath 'com.google.gms:google-services:3.0.0'

вівторок, 7 червня 2016 р. 18:24:41 UTC+3 користувач Doug Stevenson написав:

gu...@getrolo.in

unread,
Aug 12, 2016, 10:49:04 AM8/12/16
to Firebase Google Group
Bob,

I'm also facing the same issue what you have. Did you fix it? Or just bye pass by checking app size?

Keith Simmons

unread,
Sep 1, 2016, 5:47:18 PM9/1/16
to Firebase Google Group
For most users, this is almost certainly triggered by a background process.  FirebaseApp is initialized in a ContentProvider, which only runs for the main app process.  However, an overridden Application onCreate can also fire in a background process, resulting in an uninitialized exception.

Bob, I wonder if your app includes an SDK that is occasionally starting a background process in response to a rare event.

b0b

unread,
Sep 2, 2016, 12:53:24 PM9/2/16
to Firebase Google Group


On Thursday, 1 September 2016 23:47:18 UTC+2, Keith Simmons wrote:
For most users, this is almost certainly triggered by a background process.  FirebaseApp is initialized in a ContentProvider, which only runs for the main app process.  However, an overridden Application onCreate can also fire in a background process, resulting in an uninitialized exception.

Bob, I wonder if your app includes an SDK that is occasionally starting a background process in response to a rare event.


This issue still happens using the latest Firebase SDK (9.4.0) on a wide range of devices, and on all Android versions from Jelly Bean to Nougat.
This does not crash my app as I'm disabling Firebase API calls if a FirebaseApp is not available (as explained in first post), as a workaround.
However I'm still logging this issue in an online crash tracker, so I still see it happening.

Interestingly, it happens mostly only the very first time the app is started, likely after being installed from Google Play. it is as if, when the app is started for the first time,
the ContentProvider is not initialized, for whatever obscure reason.

The app does not start background processes, and doesn't use Firebase crash reporting.


Noa Drach

unread,
Sep 12, 2016, 11:25:20 AM9/12/16
to Firebase Google Group
Just started implementing Firebase Analytics usage - same error happens to me.
I'm doing the init in an overriden Application onCreate and using 'com.google.firebase:firebase-core:9.4.0' 

Not sure what are the implications of this error because I see in the console that events are supposedly sent - didn't see them in the console yet...
Reply all
Reply to author
Forward
0 new messages