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:
- Checkout from github the MCVE project
- 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 fordebug
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 fordebug
// 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:
- Created 2 years ago
- Reactions:5
- Comments:7 (1 by maintainers)
Top GitHub Comments
A quick “fix” we found was to disable the initialization of the content provider through the manifest (for UI tests only):
This helped us to bypass this bug, as we can’t disable it by any other solutions proposed by Firebase…
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