Skip to content

FirebasePerformance crash for separate process java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process #6039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexklints opened this issue Jun 16, 2024 · 6 comments
Assignees

Comments

@alexklints
Copy link

alexklints commented Jun 16, 2024

[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-perf
  • Component version: com.google.firebase:firebase-bom:33.1.0 (Reproduced since com.google.firebase:firebase-bom:31.5.0)

[REQUIRED] Step 3: Describe the problem

Calling URL.openConnection() from separate process will lead crash with Firebase Performance.
Stacktrace

FATAL EXCEPTION: DefaultDispatcher-worker-2
Process: com.alexklints.firebaseperformanceissue:Second, PID: 7698
java.lang.ExceptionInInitializerError
	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.NetworkRequestMetricBuilder.<init>(NetworkRequestMetricBuilder.java:92)
	at com.google.firebase.perf.metrics.NetworkRequestMetricBuilder.builder(NetworkRequestMetricBuilder.java:84)
	at com.google.firebase.perf.network.FirebasePerfUrlConnection.instrument(FirebasePerfUrlConnection.java:189)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.alexklints.firebaseperformanceissue:Second. 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:92)
	at com.google.firebase.perf.config.RemoteConfigManager.<init>(RemoteConfigManager.java:86)
	at com.google.firebase.perf.config.RemoteConfigManager.<clinit>(RemoteConfigManager.java:53)
	... 16 moreFATAL EXCEPTION: DefaultDispatcher-worker-2

Steps to reproduce:

  1. Add Firebase Perf to project.
  2. Make network request with UrlConnection from activity.
  3. All works.
  4. Than move activity to separate process. Activity just for simple example. It can be a service in a separate process.
  5. Crash occurs.
  6. Expected behavior: Requests will be executed correctly in a separate process without activating FirebaseApp.

It works correct up to com.google.firebase:firebase-bom:31.0.0.

Relevant Code:

Example with network request from separate process

@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@lehcar09
Copy link
Contributor

Hi @alexklints, thank you for for reaching out and raising the issue. Thank you for sharing an MCVE. I was able to reproduce the issue from version 31.2.0 up to the latest version. I'll notify our engineers about and see what we can do here. Thanks!

@mrober mrober self-assigned this Jun 18, 2024
@mrober
Copy link
Contributor

mrober commented Jun 18, 2024

Firebase only initializes automatically on the default process of an app. If you have a multi-process app, you need to initialize manually in each process or not use Firebase in the other processes.

To initialize manually, you could do something like this:

class MyApp : Application() {
  override fun onCreate() {
    super.onCreate()

    // Initialize Firebase in other processes.
    if (getProcessName() != applicationInfo.processName) {
      FirebaseApp.initializeApp(applicationContext)
    }
  }
}

@alexklints
Copy link
Author

Hi.

I understand, but the thing is, the behavior used to be different. Firebase Performance did not attempt to intercept the network if there was no initialization in the process. There are such examples of an issue where developers tried to implement this behavior:

@mrober
Copy link
Contributor

mrober commented Jun 28, 2024

I took a look, and this was fixed in Firebase Perf 21.0.1, can you try the latest version @alexklints?

@mrober
Copy link
Contributor

mrober commented Jul 2, 2024

Please open a new issue if this was not resolved in the latest version for you.

@mrober mrober closed this as completed Jul 2, 2024
@firebase firebase locked and limited conversation to collaborators Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants