Open hram opened 1 year ago
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
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:
firebase-bom:31.2.0
and not 31.2.2
.firebase-bom:32.1.1
firebase-bom:31.1.1
and below) the issues doesn't happens! Only on fresh installs that have changes from firebase-bom:31.2.0
and above.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:
apply plugin: 'com.google.gms.google-services'
to app/build.gradle
.classpath 'com.google.gms:google-services:4.3.4'
to build.gradle
and clicked Sync 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.
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
@hram Did the above suggestion work for you? Suggestions in this comment .
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.
[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:
[REQUIRED] Step 2: Describe your environment
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
Relevant Code: