question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FirebasePerformance.getInstance() is crashing on instrumented unit tests

See original GitHub issue

Describe your environment

  • Android Studio version: 2020.3.1 Patch 3 (Arctic Fox)
  • Firebase Component: Performance
  • Component version: 20.0.0 (usage through BOM 28.0.0)

Describe the problem

Getting this crash when running instrumented unit tests:

java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.hadisatrio.apps.android.repro.test. Make sure to call FirebaseApp.initializeApp(Context) first.
    at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:183)
    at com.google.firebase.perf.FirebasePerformance.getInstance(FirebasePerformance.java:132)
    at com.google.firebase.perf.FirebasePerformanceInitializer.onAppColdStart(FirebasePerformanceInitializer.java:29)
    at com.google.firebase.perf.application.AppStateMonitor.sendAppColdStartUpdate(AppStateMonitor.java:274)
    at com.google.firebase.perf.application.AppStateMonitor.onActivityResumed(AppStateMonitor.java:195)
    at android.app.Application.dispatchActivityResumed(Application.java:455)
    at android.app.Activity.dispatchActivityResumed(Activity.java:1295)
    at android.app.Activity.onResume(Activity.java:1827)
    at androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity.onResume(InstrumentationActivityInvoker.java:164)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1454)
    at androidx.test.runner.MonitoringInstrumentation.callActivityOnResume(MonitoringInstrumentation.java:762)
    at android.app.Activity.performResume(Activity.java:8103)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4441)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4483)
    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2175)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:7860)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

This happened on all tests that uses ActivityScenario#launch(Activity), starting from Performance 20.0.0. Earlier releases worked fine without any code change.

Steps to reproduce:

On an Android project with Firebase Performance setup:

  1. Create an empty library module (say. :module)
  2. Add a dependency to firebase-perf within the module
  3. Create an empty activity
  4. Add the test shown below within androidTest directory
  5. ./gradlew module:connectedCheck

…or…

  1. Download & extract MCVE.zip
  2. Add your google_services.json file within :app
  3. ./gradlew module:connectedCheck

Relevant Code:

class Repro {

    @Test // This will fail with the above stacktrace
    fun activityScenario() {
        ActivityScenario.launch(MainActivity::class.java).use {
            print(0)
        }
    }

    @Test // This will pass
    fun nonActivityScenario() {
        print(0)
    }
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Flyktsodancommented, Nov 1, 2022

Any update on this? tried with all latest version(s) and still the same issue.

It breaks all Compose Layout tests in Library modules 😿

1reaction
argzdevcommented, Nov 15, 2021

Hi @MrHadiSatrio, thanks for the details. I was able to repro the issue, I’ll try to get in contact with an engineer and see what we can find.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FirebaseCrashlytics.getInstance() is Crashing App In Multi ...
When calling FirebaseCrashlytics.getInstance() in Activity with another Process the App just crashes without generating any single Stack Trace ...
Read more >
Firebase Android SDK Release Notes - Google
Firebase ML Model Downloader version 24.0.2. Fixed an issue where FirebaseModelDownloader.getInstance would crash when using non-default FirebaseApp instances.
Read more >
Does Unit-Tested Code Crash? A Case Study of Eclipse - arXiv
Unit -testing, crash incident reports, code coverage, stack traces, software reliability. ∗Chioteli collected the unit testing results and performed the ...
Read more >
Crash with ProGuard and Firebase Crashlytics - Google Groups
The release version of the app crashes immediately when opened ... callApplicationOnCreate(Instrumentation.java:1189) ... getInstance()
Read more >
Android Instrumented Test crash on Emulator - CircleCI Discuss
Hi, I am building my application with CircleCI. My Instrument tests were running just fine until I extended those with more complicated tests...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found