firebase-android-sdk
firebase-android-sdk copied to clipboard
FirebaseApp is not initialized in this process
[READ] Step 1: Are you in the right place?
Issues filed here should be about bugs in the code in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:
- For general technical questions, post a question on StackOverflow with the firebase tag.
- For general Firebase discussion, use the firebase-talk google group.
- For help troubleshooting your application that does not fall under one of the above categories, reach out to the personalized Firebase support channel.
[REQUIRED] Step 2: Describe your environment
- Android Studio version:
- Firebase Component: com.google.firebase:firebase-bom:31.2.2
- Component version:
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
- Add annotation @AddTrace to function onCreate() in the Application class
- Init firebase FirebaseApp.initializeApp(this) inside function onCreate()
- Start app
- Application crashes on startup
Relevant Code:
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process <my app id>:Metrica. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:179)
at com.google.firebase.perf.config.RemoteConfigManager.getInitialStartupMillis(RemoteConfigManager.java:91)
at com.google.firebase.perf.config.RemoteConfigManager.<init>(RemoteConfigManager.java:85)
at com.google.firebase.perf.config.RemoteConfigManager.<clinit>(RemoteConfigManager.java:52)
at com.google.firebase.perf.config.RemoteConfigManager.getInstance(RemoteConfigManager.java:119)
at com.google.firebase.perf.config.ConfigResolver.<init>(ConfigResolver.java:78)
at com.google.firebase.perf.config.ConfigResolver.getInstance(ConfigResolver.java:86)
at com.google.firebase.perf.application.AppStateMonitor.<init>(AppStateMonitor.java:98)
at com.google.firebase.perf.application.AppStateMonitor.getInstance(AppStateMonitor.java:87)
at com.google.firebase.perf.metrics.Trace.<init>(Trace.java:106)
at com.google.firebase.perf.metrics.Trace.create(Trace.java:98)
at com.google.firebase.perf.FirebasePerformance.startTrace(FirebasePerformance.java:213)
at <my app id>.App.onCreate(Unknown Source:6)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5791)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Hi @hram, thanks for reaching out to us. I'm not experiencing the same behavior with the steps you've provided. I added @AddTrace to my application class, but there seems to be no issue.
Relevant code:
class MainApplication: Application() {
@AddTrace(name = "onCreateTrace", enabled = true /* optional */)
override fun onCreate() {
FirebaseApp.initializeApp(this)
super.onCreate()
}
}
Dependencies:
implementation platform('com.google.firebase:firebase-bom:31.2.2')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-perf-ktx'
Manifest:
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
...
android:name=".MainApplication"
tools:targetApi="31">
Am I missing anything?
Hey @hram. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
@argzdev I believe the app has to startup a separate process where onCreate
is called again. It seems Firebase now fails to initialize on non main processes.
<service
android:name="com.company.NewProcess"
android:process=":NewProcess" />
Starting this service would result in a crash.
Hi @tevjef, thanks for the insight. I'm not sure if I'm doing something wrong, but I still can't replicate the same behavior even with the service.
AndroidManifest:
<application
...
<service
android:name=".RandomService"
android:process=":NewProcess" />
</application>
Random Service code:
class RandomService: Service() {
override fun onBind(p0: Intent?): IBinder? = null
@AddTrace(name = "onCreateServiceTrace", enabled = true)
override fun onCreate() {
super.onCreate()
Log.d(TAG, "onCreate: ")
FirebaseApp.initializeApp(this)
}
@RequiresApi(Build.VERSION_CODES.O)
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
Log.d(TAG, "onStartCommand: ")
return START_STICKY
}
override fun onDestroy() {
super.onDestroy()
stopForeground(STOP_FOREGROUND_REMOVE)
stopSelf()
Log.d(TAG, "Random Service is being killed")
}
}
MainActivity:
fun startRandomService(view: View) {
Intent(this, RandomService::class.java).also { intent ->
startService(intent)
}
}
fun endRandomService(view: View) {
Intent(this, RandomService::class.java).also { intent ->
stopService(intent)
}
}
@argzdev why do you call FirebaseApp.initializeApp(this) before super.onCreate()? what happens if you put FirebaseApp.initializeApp(this) after super.onCreate()?
Hi @hram, I tried it with both scenario (before or after onCreate()
), but still unable to reproduce this behavior. I'm not sure what I'm missing here. That said, any chance you could share us a minimal reproducible example so I can investigate this further? Thanks!
Hey @hram. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
@argzdev https://github.com/tevjef/android-bugs/tree/firebase-android-sdk-issues-4693
When launching the app:
Observe firebase is initialized properly. Click the Next button to start a service in a new process Observe failure in Logcat this error
java.lang.ExceptionInInitializerError
at com.google.firebase.perf.config.RemoteConfigManager.getInstance(RemoteConfigManager.java:119)
at com.google.firebase.perf.config.ConfigResolver.<init>(ConfigResolver.java:78)
at com.google.firebase.perf.config.ConfigResolver.getInstance(ConfigResolver.java:86)
at com.google.firebase.perf.application.AppStateMonitor.<init>(AppStateMonitor.java:98)
at com.google.firebase.perf.application.AppStateMonitor.getInstance(AppStateMonitor.java:87)
at com.google.firebase.perf.metrics.Trace.<init>(Trace.java:106)
at com.google.firebase.perf.metrics.Trace.create(Trace.java:98)
at com.google.firebase.perf.FirebasePerformance.startTrace(FirebasePerformance.java:213)
at com.example.myapplication.App.onCreate(Unknown Source:2)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1266)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6785)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2134)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.myapplication:NewProcess. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:179)
at com.google.firebase.perf.config.RemoteConfigManager.getInitialStartupMillis(RemoteConfigManager.java:91)
at com.google.firebase.perf.config.RemoteConfigManager.<init>(RemoteConfigManager.java:85)
at com.google.firebase.perf.config.RemoteConfigManager.<clinit>(RemoteConfigManager.java:52)
at com.google.firebase.perf.config.RemoteConfigManager.getInstance(RemoteConfigManager.java:119)
at com.google.firebase.perf.config.ConfigResolver.<init>(ConfigResolver.java:78)
at com.google.firebase.perf.config.ConfigResolver.getInstance(ConfigResolver.java:86)
at com.google.firebase.perf.application.AppStateMonitor.<init>(AppStateMonitor.java:98)
at com.google.firebase.perf.application.AppStateMonitor.getInstance(AppStateMonitor.java:87)
at com.google.firebase.perf.metrics.Trace.<init>(Trace.java:106)
at com.google.firebase.perf.metrics.Trace.create(Trace.java:98)
at com.google.firebase.perf.FirebasePerformance.startTrace(FirebasePerformance.java:213)
at com.example.myapplication.App.onCreate(Unknown Source:2)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1266)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6785)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2134)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Thanks @tevjef, I was able to reproduce the same behavior now. I'll notify our engineers.
Hi @argzdev Any update on this ? ...
I'm trying to create foregroundService with new process and my service has some firebase usage .I'm getting error Default FirebaseApp is not initialized in this process com.example.dev:locationProcess.
Hi all, sorry for the radio silence. Our engineers are currently working on other issues at the moment. However, rest assured that this will be worked on as soon as possible. That said, I'd like to ask for help to kindly give an emoji thumbs up on the original author's post for tracking. This'll help us prioritize issues based on severity and demand. Thanks!
We also facing this issue when start a service in new process. The crash still happing in firebase BoM version com.google.firebase:firebase-bom:31.3.0. After investigating, the crash only happened if we used Firebase Perf in our app. We need to upgrade firebase-BoM because of this warning:

How it's goin?
Let me notify our engineers again and see if we can get some updates.
iam also getting the same error
//app gradle implementation 'com.google.android.gms:play-services-maps:18.1.0' implementation 'com.google.firebase:firebase-crashlytics:18.3.7' implementation 'com.google.firebase:firebase-analytics:21.2.2'
//project level classpath 'com.google.gms:google-services:4.3.15' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.5'
//Application class override fun onCreate() { super.onCreate() FirebaseApp.initializeApp(this) FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true)
}
iam able to open the app in debug mode but iam not able to open the release build ,when iam trying to open the release build iam getting the issue as mentioned below.
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process <com.appID>. Make sure to call FirebaseApp.initializeApp(Context) first. at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:179)
Hi @vineeshLee, looking at your imports I don't see firebase-perf
, so I'm not sure if you're experiencing the same issue here. Can you provide a full stacktrace so we can conduct an initial investigation?
Sorry to be a pain but are there any updates about this issue?
The only way I have found so far to circumvent it if you're using an SDK that has a remote process is by manually initialising Firebase and making sure it gets initialised before the SDK in question...
Sorry for the radio silence here, @ThrowJojo. Our engineers are still working on this. We'll reply back here once we have further updates. Thanks!
h @argzdev , are there any updates.
Let me share some new information on this issue:
- The issue first appeared in
firebase-bom:31.2.0
and not31.2.2
. - The issue still exists in the latest version
firebase-bom:32.1.1
- The issue seems related to runtime configuration, in case of upgrading the application (with changes from
firebase-bom:31.1.1
and below) the issues doesn't happens! Only on fresh installs that have changes fromfirebase-bom:31.2.0
and above. - Based on the error message and the version the culprit is likely standard Firebase executors:
Thanks a lot for highlighting the issue. Similar to the reference mentioned above, this issue seem to be raising out of Firebase Performance/Remote Config using the Firebase executors instead of its own executors. We are working to reproduce/fix this issue at the earliest. Will keep this issue posted as and when we have updates.
Thanks for your patience as we work through this issue.
I have the same problem
any update?
putting 'com.google.gms.google-services' on plugins in app/build.gradle solved my problem
plugins {
id 'com.google.gms.google-services'
}
this is open from February, when can we expect it's resolution
I have the same problem
So I was facing this problem and I'm working with React Native and in this case was integrating push notification for android with Braze and FCM. I did the following:
- Open Android Studio.
- Added
apply plugin: 'com.google.gms.google-services'
toapp/build.gradle
. - Also added
classpath 'com.google.gms:google-services:4.3.4'
tobuild.gradle
and clickedSync Now
and that fixed my issue.
Also in my case didn't have to add this FirebaseApp.initializeApp(this)
... it worked with the above steps.
After detailed analysis, here are our learnings on the issue:
Possibility 1:
Firebase App can be initialized in multiple ways - Either through dependency on Google Services (using the plugin) or using configuration options. When using configuration options based initialization, typically this is done in the Application onCreate
API. When using @AddTrace
annotation for the Application's onCreate
API, that would force referring to FirebaseApp's instance at the start of the onCreate
function. Unfortunately that is going to cause an exception since FirebaseApp is not initialized in the beginning of the onCreate
method. There is no cleaner way to fix this issue.
The recommendation in this case would be to refactor the implementation on the application's onCreate
API into its own separate function and add @AddTrace
annotation to that instead of the application's onCreate
function. This should avoid the problem.
Possibility 2:
Like the last comment above, you can depend on the GoogleServices which will initialize FirebaseApp before the Application's onCreate
that can avoid the exception. That is exactly the reason why we did not have to do a separate FirebaseApp.initializeApp()
in this approach.
But the caveat in this approach would be to avoid analytics dependency since that is not currently supported.
Note: We don't this is exactly because of the changes brought because of the Firebase Executor that has caused this issue. But changing to FirebaseExecutor has brought this needs to visibility (since FirebaseExecutor based approach avoids FirebaseApp initialization to later until necessary).
Please update the comment thread if the above approaches does not solve your problem.
please note that this is occuring too when app has to startup a separate process , related to Firebase initialization on non main processes.