FirebaseApp is not initialized in this process
hram opened this issue · 66 comments
[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!
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!
Let me share some new information on this issue:
- The issue first appeared in
firebase-bom:31.2.0and 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.1and below) the issues doesn't happens! Only on fresh installs that have changes fromfirebase-bom:31.2.0and 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.gradleand clickedSync Nowand 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.
Same problem in .NET MAUI 😢
For MAUI I can confirm that adding Xamarin.GooglePlayServices.Analytics to your project (binding library for the above mentioned google services analytics package) work.
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!
do not close it automatically
Hi, any progress on this issue?
Thật đáng tiếc vì đến bây giờ sự cố vẫn chưa đc khắc phúc
I have the same issue with my application that have foreground service as a separated process.
Without FirebaseApp.initializeApp() there are no initialization at all, adding this in onStartCommand() does the job, but only for service.
Adding FirebaseApp.initializeApp() into the application's onCreate make app crash when open for some users. Seems like for some reason firebase cannot be used in more than one process for some reason.
classpath 'com.google.gms:google-services:4.3.8' is OK but classpath 'com.google.gms:google-services:4.4.0' crash
In my case helped downgrade google-services from 4.4.0 to 4.3.15
gradle wrapper: 7.5.1
android gradle plugin: 7.3.1
crashlytics gradle plugin: 2.9.9
google-services: 4.3.15 (4.4.0)
firebase bom: 32.5.0
I faced same issue today.i tried everthing and at the end of the day it fixed🥴 .
i'm adding build.gradle(project/module) here
Build.gradle(Project)
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
}
Build.gradle(Module)
plugins {
id 'com.android.application'
}
android {
namespace 'tech.bugscreator.smartpay'
compileSdk 34
defaultConfig {
applicationId "tech.bugscreator.smartpay"
minSdk 24
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.android.material:material:1.10.0'
implementation(platform("com.google.firebase:firebase-bom:32.5.0"))
implementation("com.google.firebase:firebase-analytics")
implementation("com.google.firebase:firebase-firestore")
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
apply plugin: 'com.google.gms.google-services'
i added google service dependency using classpath and in module level i apply plugin and it resolved my issue
was facing issue with 'com.google.gms:google-services:4.4.0' but it solved when i changed it to 4.3.0 , Thanks to @engineerStuardo
Any work around for this issue? While we wait for the next update that hopefully fixes it
I even tried to downgrade to 4.3.15 and it still happening :-(
Downgrade to 4.3.15 helps to me
@engineerStuardo Thank you. Its really helped. version : 4.3.4
classpath 'com.google.gms:google-services:4.3.8' is OK but classpath 'com.google.gms:google-services:4.4.0' crash
thanks!!!!!!!!!!
classpath 'com.google.gms:google-services:4.3.8' is OK but classpath 'com.google.gms:google-services:4.4.1' crash
classpath 'com.google.gms:google-services:4.3.8' is OK but classpath 'com.google.gms:google-services:4.4.0' crash
thank you bro!
Hi @visumickey and @argzdev do we have any update on the fix.
I am still experiencing this issue and I tried the recommended fixes above and nothing works for me(unless downgrading dependencies, which is not what we want to do at the moment).
The original problem was related to the :Metrica process (it is an analytics service of Yandex, the largest advertising provider in the CIS). In new versions of the library, the process has been renamed to :AppMetrica
The problem can be solved as follows:
class App : Application() {
var mainProcess = false
var metricaProcess = false
override fun onCreate() {
val processName = ProcessUtil.getProcessName(this)
mainProcess = processName==packageName
metricaProcess = processName.contains(":AppMetrica") || processName.contains(":Metrica")
if (!metricaProcess) { // you do not need to initialise anything manually inside the Metrica process
if (!mainProcess) {
// if you created the service yourself in a separate process (via android:process=":Something"), you should manually initialise Firebase in that process.
FirebaseApp.initializeApp(this)
}
// put old onCreate code here, e.g:
// FirebaseCrashlytics.getInstance().setUserId("someId")
// if (mainProcess) MobileAds.initialize(this) { } // you probably don't want ads in the background process
// ...
}
super.onCreate()
}
}
ProcessUtil.java:
https://gist.github.com/vellrya/6ab5d915f1002a8e1ae3205ba715f0d7
This method works with the newest versions of libraries, there is no need to downgrade dependency versions.
Yes, i just updated com.google.gms:google-services from 4.3.15 to 4.4.1 and it's started crashing for me for above issue. Added initialization in Activity as well as in APplication file, still crashes for me.
Line where it's breaking for above error, even i tried to initialize FirebaseApp before i am using that, still not fixed
FirebaseAuth.getInstance().currentUser
I have tested the following versions of com.google.gms:google-services:
4.3.15: working ✅
4.4.0: not working ❌
4.4.1: not working ❌
Firebase (Flutter) versions:
firebase_core: ^2.27.1
firebase_auth: ^4.17.9
firebase_messaging: ^14.7.20Hi, any progress on this issue? com.google.gms:google-services 4.4.1: not working
I had this same issue due to an Activity being designated to a separate process. Downgrading versions did not work for me. However, manually initializing Firebase as outlined in #4599 resolved the issue.
- Disable the
FirebaseInitProviderin the AndroidManifest - Manually initialize Firebase in your Application via
FirebaseApp.initializeApp(this, builder.build())
Unfortunately manually initializing Firebase apparently breaks _app_start tracing with BOM version 32.2.0 or later.
集成了下面的sdk 功能, firebase-crashlytics 统计到线上用户报错 Caused by java.lang.IllegalStateException
Default FirebaseApp is not initialized in this process com.moonjoy.cointalh. Make sure to call FirebaseApp.initializeApp(Context) first.
本地无法复现。请问是什么问题导致的?
classpath 'com.google.gms:google-services:4.3.15'
implementation 'com.google.firebase:firebase-crashlytics:18.6.4'
implementation 'com.google.firebase:firebase-analytics:21.6.2'
// Firebase Performance Monitoring 对勾
implementation ('com.google.firebase:firebase-perf:20.5.2'){
exclude group: 'com.squareup.okhttp3'
}
// Firebase messaging
implementation 'com.google.firebase:firebase-messaging:23.4.1'
// Firebase config
implementation 'com.google.firebase:firebase-config:21.6.3'
Same here, upgrading to "com.google.gms:google-services:4.4.2" breaks my app. I will stay with "com.google.gms:google-services:4.3.10" until it gets resolved
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!
Any update on this @argzdev ? 😅😅
Same here, upgrading to "com.google.gms:google-services:4.4.2" breaks my app. I will stay with "com.google.gms:google-services:4.3.10" until it gets resolved
Same for me
it seems that it could be due to some refactoring: google/play-services-plugins#269
News: https://github.com/google/play-services-plugins/tree/main/google-services-plugin#new-in-version-440
Place the google-services.json file for your project in the app/ directory.
Alternatively, you can use variant specific source-sets, for example: debug/google-services.json.
This did trigger the error Default FirebaseApp is not initialized in this process
Related issues:
4.3.15는 괜찮은것 같습니다.
Any progress on this issue? Even I am facing it after upgrading Firebase BoM to 33.2.0
Here's what the Javadoc from the FIrebaseApp.java class says :-
"Any FirebaseApp initialization must occur only in the main process of the app. Use of Firebase in processes other than the main process is not supported and will likely cause problems related to resource contention."
So, going by the maintainers' recommendation, we're not supposed to initialize Firebase in non-main processes. I did initalize Firebase in a non-main process in the Application onCreate() and it did stop the crash, but I'm not sticking to this solution because it may have side effects that may only be realized in production.
If an exception is going to be thrown then we should be allowed to catch it. At the very least this should be failing gracefully. Analytics should not be crashing apps in production.
Hi @visumickey and @argzdev do we have any update on the fix.
Knock-knock-knock, is there any update?
@ernazarsembayev we landed a fix for this, it will go out in the next-next release due to timing.
This fix was released in Perf version 21.0.2
