Skip to content
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

FirebasePerformance.getInstance() is crashing on instrumented unit tests #3114

Closed
MrHadiSatrio opened this issue Nov 9, 2021 · 8 comments
Closed
Assignees
Labels
api: performance type: bug Something isn't working

Comments

@MrHadiSatrio
Copy link

MrHadiSatrio commented Nov 9, 2021

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)
    }
}
@argzdev
Copy link
Contributor

argzdev commented Nov 9, 2021

Hi @MrHadiSatrio, thanks for reporting. It seems that this issue is replicable when id 'com.google.gms.google-services' is not added in your build.gradle file.

build.gradle in app module:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'com.google.gms.google-services'
}

build.gradle in project:

dependencies {
    classpath "com.android.tools.build:gradle:7.0.1"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"
    classpath 'com.google.gms:google-services:4.3.10'
}

Could you check if adding these work? Thanks.

@MrHadiSatrio
Copy link
Author

@argzdev, adding the plugin did not solve the problem for me; the tests still fail with an identical stack trace.

The only thing that worked was disabling FirebasePerfProvider through tools:remove in the Manifest. (A similar finding also posted here.)

@argzdev
Copy link
Contributor

argzdev commented 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.

@visumickey
Copy link
Contributor

@MrHadiSatrio I tried reproducing the issue based on the steps you provided. But unfortunately I'm not able to do the same. I'm sure there is something I have missed. Can you please help me reproduce the issue?

Here is my sample project. Please make sure to add your google_services.json file to make sure you are able to move ahead on this.

If there are any changes pending, please let me know.

@MrHadiSatrio
Copy link
Author

@visumickey, I was able to repro it on your sample project. Could you try adding the dependency to firebase-perf within :module and re-run the test?

I'll edit my initial post to include this in the STR.

@argzdev argzdev added type: bug Something isn't working and removed needs-attention labels Nov 18, 2021
@Flyktsodan
Copy link

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

It breaks all Compose Layout tests in Library modules 😿

@Flyktsodan
Copy link

A temporary (not so much) workaround we have implemented is to add a separate manifest in the androidTest folder that removes the plugin.

`

<application android:theme="@style/Theme.AppCompat.Light">

    <!--
        Disables the Firebase Performance plugin for android tests.
        There is a issue where the plugin will crash Instrumented
        tests in Library modules when the application is created.

        See: https://github.com/firebase/firebase-android-sdk/issues/3114 for more info
    -->
    <provider
        android:name="com.google.firebase.perf.provider.FirebasePerfProvider"
        android:authorities="${applicationId}.firebaseperfprovider"
        tools:node="remove" />

</application>
`

@mrober
Copy link
Contributor

mrober commented Oct 2, 2024

This should have been fixed over a year ago by #4242 can you please try the latest version of Perf and open a new issue if the problem persists, thanks!

@mrober mrober closed this as completed Oct 2, 2024
@firebase firebase locked and limited conversation to collaborators Nov 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: performance type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants