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

Crash with firebase-perf:20.0.0 when google-service plugin is disabled. #2707

Closed
eric-labelle opened this issue Jun 2, 2021 · 9 comments
Closed

Comments

@eric-labelle
Copy link

[REQUIRED] Step 2: Describe your environment

  • System
    • Android Studio 4.2.1
    • Build #AI-202.7660.26.42.7351085, built on May 10, 2021
    • Runtime version: 11.0.8+10-b944.6916264 x86_64
    • VM: OpenJDK 64-Bit Server VM by N/A
    • macOS 10.16
  • Library
    • Firebase Component: Performance
    • Component version: 20.0.0

[REQUIRED] Step 3: Describe the problem

The firebase-perf library version 20.0.0 does not seems to be working well when the google-service is disabled and crash with the following stacktrace:

W/FirebaseApp: Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.
I/FirebaseInitProvider: FirebaseApp initialization unsuccessful
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myapplication.firebase.perfbug.debug, PID: 9406
    java.lang.RuntimeException: Unable to resume activity {com.example.myapplication.firebase.perfbug.debug/com.example.myapplication.firebase.perfbug.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.myapplication.firebase.perfbug.debug. Make sure to call FirebaseApp.initializeApp(Context) first.
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4205)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4237)
        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:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.myapplication.firebase.perfbug.debug. 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:131)
        at com.google.firebase.perf.FirebasePerformanceInitializer.onAppColdStart(FirebasePerformanceInitializer.java:29)
        at com.google.firebase.perf.application.AppStateMonitor.sendAppColdStartUpdate(AppStateMonitor.java:271)
        at com.google.firebase.perf.application.AppStateMonitor.onActivityResumed(AppStateMonitor.java:192)
        at android.app.Application.dispatchActivityResumed(Application.java:436)
        at android.app.Activity.dispatchActivityResumed(Activity.java:1265)
        at android.app.Activity.onResume(Activity.java:1789)
        at androidx.fragment.app.FragmentActivity.onResume(FragmentActivity.java:433)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1446)
        at android.app.Activity.performResume(Activity.java:7939)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4195)

Using version 19.1.1 the same 2 logs are printed, but the app isn't crashing and there are no stacktraces

W/FirebaseApp: Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.
I/FirebaseInitProvider: FirebaseApp initialization unsuccessful

Steps to reproduce:

  1. Checkout from github the MCVE project
  2. Launch the debug variant

Expected:
No crash

Actual:
Crash (see stacktrace below)

Workaround:
Downgrade / Keep firebase-perf library to version 19.1.1
or
Stop disabling the google-service plugin for specific variants.

  • The reason why I disabled the google-service is because we have multiple variants that have applicationIdSuffix and they don't need to all be in google analytics / firebase console
  • The reason why I disabled the firebase-perf plugin is mainly to speed up development locally, eliminate all logs from firebase in logcat and also to make sure UITests execution do not affect stats in the Console.

Relevant Code:

Important

  • the google-service plugin is disabled for debug
android.applicationVariants.configureEach {
    val variant = this as com.android.build.gradle.internal.api.ApplicationVariantImpl
    // The plugin must be disabled for debug otherwise we need to setup all appId in Firebase.
    if (variant.name.startsWith("debug")) {
        logger.lifecycle("Disabling google-service plugin for $name")
        project.tasks.named("process" + name.capitalize() + "GoogleServices").configure {
            enabled = false
        }
    }
}
  • the firebase-perf plugin is disabled for debug
// Disable Firebase perf on debug
with((this as ExtensionAware).extensions["FirebasePerformance"] as com.google.firebase.perf.plugin.FirebasePerfExtension) {
         setInstrumentationEnabled(false)
}
  • the automatic collection is disabled for debug through /src/debug/AndroidManifest
 <meta-data
            android:name="firebase_performance_collection_deactivated"
            android:value="true" />

I believe the culprit might be related to the following PR #2518 which in theory might be what's behind "Improve the launch time of the SDK." from the release notes for 20.0.0 but it's hard to say since releases are not flagged on this repository. More specifically the commit ca3b9390689d20f39589068d9ebb73e07d955367 which add the coldStart callback fetching the instance with FirebasePerformance.getInstance()

Thanks for your time and let me know if there's any other workaround you can suggest, but until then we cannot upgrade to the version 20.0.0.

@aguatno
Copy link

aguatno commented Jun 3, 2021

Hi @eric-labelle thanks for reporting and for sharing the MCVE. Let me check this and will get back to you for more updates. Thanks

@aguatno aguatno self-assigned this Jun 3, 2021
@eric-labelle
Copy link
Author

Any updates on this @aguatno ?
Thanks

@aguatno
Copy link

aguatno commented Aug 4, 2021

Hi @eric-labelle apologies for the delay here. We appreciate the thorough information that you shared here.

Hi @visumickey I'd like to confirm if this is intended or not? It seems the issue is reproducible (see mcve) even with the latest SDK. I'm guessing there are compatibility problems with the version of google-services and Firebase versions.

@aguatno aguatno removed their assignment Aug 4, 2021
@PhilippeBoisney
Copy link

We have the same issue, but it concerns our UI tests that crash with the same error on version com.google.firebase:firebase-perf:20.0.2

@PhilippeBoisney
Copy link

A quick "fix" we found was to disable the initialization of the content provider through the manifest (for UI tests only):

 <provider
            android:name="com.google.firebase.perf.provider.FirebasePerfProvider"
            android:authorities="${applicationId}.firebaseperfprovider"
            tools:node="remove" />

This helped us to bypass this bug, as we can't disable it by any other solutions proposed by Firebase...

@visumickey
Copy link
Contributor

Thanks for the details on the bug and sorry for the delay in responding. I re-used the same project provided and I was able to reproduce the issue with the firebase performance version 20.0.0. But when I moved to the recent version of Firebase performance SDK (20.0.3), I don't see the crash happening anymore.

Can you try upgrading to the recent version of the SDK and check if you are still seeing the crash?

@eric-labelle
Copy link
Author

Hi, I just tried again bumping to 20.0.3 and I still have the crash.
Also tried bumping googleservice plugin to 4.3.10, no success there either. No sure how you got it to work..

@fryette
Copy link

fryette commented Dec 29, 2022

@visumickey even now crash happens with all the latest SDKs.

@Anigif
Copy link

Anigif commented Jun 7, 2023

I think this was solved after #4242 was merged. We have previously used @PhilippeBoisneys's solution (and thanks a lot for that!) but after FirebasePerfProvider was removed, linting complained and I simply tried to removed those - and now it seems to work for our part (without having 100% tested all cases yet).

@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.
Projects
None yet
Development

No branches or pull requests

9 participants