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.

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

See original GitHub issue

[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 https://github.com/firebase/firebase-android-sdk/pull/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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
PhilippeBoisneycommented, Oct 14, 2021

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…

1reaction
PhilippeBoisneycommented, Sep 17, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - How to fix google play service error - Stack Overflow
Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies. build.gradle script : apply plugin: 'com.android.
Read more >
The Google Services Gradle Plugin
The google-services plugin has two main functions: Process the google-services.json file and produce Android resources that can be used in your application's ...
Read more >
Get started with Performance Monitoring for Android - Firebase
Step 2: Add the Performance Monitoring Gradle plugin to your app · Disable the Performance Monitoring plugin for your debug builds at compile...
Read more >
capacitor-crashlytics-cc-fork - npm
Latest version: 0.0.1, last published: 3 years ago. ... Capacitor plugin to enable features from Firebase Crashlytics. Android coming soon.
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