Can't disable Crashlytics in a Firebase app (anymore)
Asked Answered
I

3

16

After upgrading to com.crashlytics.sdk.android:crashlytics:2.7.1@aar (from 2.6.8), I can't disable Crashlytics anymore in my Firebase app.

Looks like there's some code in Crashlytics library itself that initializes Fabric with Crashlytics kit enabled whenever it detects that it's running inside a Firebase application. Indeed initializing with Crashlytics enabled and with ext.enableCrashlytics = false throws an UnmetDependencyException and crashes the app at startup (in fact, before my code in Application.onCreate runs).

Does anyone know a workaround for that? Sticking with 2.6.8 works for now. This is what I have in my code that used to work until an upgrade:

app/build.gradle:

ext.enableCrashlytics = false

Application.java (onCreate, full method body as requested):

super.onCreate();
if (LeakCanary.isInAnalyzerProcess(this)) {
    return;
}
LeakCanary.install(this);
// First Fabric invocation
Fabric.with(this, new Crashlytics.Builder().core(
    new CrashlyticsCore.Builder().disabled(true).build()).build());
RxJavaPlugins.setErrorHandler(e -> LOGGER.error("Undeliverable RxJava error", e));
// First Firebase invocation
FirebaseDatabase db = FirebaseDatabase.getInstance();
if (BuildConfig.DEBUG) {
    db.setLogLevel(com.google.firebase.database.Logger.Level.DEBUG);
}
db.setPersistenceEnabled(true);
Ignite answered 22/10, 2017 at 19:52 Comment(4)
After reading your post, I did the same upgrade to 2.7.1 and don't get the crash, although the first build failed and I had to Clean the project and rebuild. It looks like your setup is correct as described in the documentation.Marbleize
Mike from Fabric here. I'm looking into this further, but can you share your Firebase init code as well? Specifically the ordering of Firebase and Fabric, which comes first?Pelerine
@BobSnyder: I tried Clean and Rebuild, also "Invalidate cache and Restart" in Android Studio and unfortunately it didn't help. Thanks for the hint though!Ignite
@MikeBonnell: thanks for taking a look, updated the post.Ignite
P
23

Mike from Fabric here. Use:

<meta-data android:name="firebase_crashlytics_collection_enabled" android:value="false" />

if you want to disable Crashlytics while using Firebase.

Pelerine answered 23/10, 2017 at 15:20 Comment(8)
Thanks Mike! Is there any way to disable Crashlytics conditionally (outside the build type which the manifest is bound to)?I don't want Crashlytics reports for my "instrumented" buildType from developers' workstations, but I do want Crashlytics reports from the build server, so I check an environment variable in build.gradle to conditionally set enableCrashlytics to true / false.Ignite
@J.Williams: Would a manifestPlaceholder for the value of firebase_crashlytics_collection_enabled do what you need?Marbleize
@Mike is there a way to disable Crashlytics (while using Firebase) for iOS, too? Just for Debug-buildsGeneration
@Generation Take a look here: #28931822Pelerine
Hi, Mike! Would you please add this instruction on official site docs.fabric.io/android/crashlytics/… ?Breault
Thanks for the suggestion @nick_kryloff. We have it listed here: firebase.google.com/docs/crashlytics/… but I'll share the feedback with the team.Pelerine
Hi Mike, when I use this meta tag I understand I would have to call "Fabric.with(this, new Crashlytics())" to enable Crashlytics again. Would this then be enabled in a persistent way or would I need to call the code again when the app is restarted? I'm asking as crash reports should be optional for GDPR and calling this code in every activity/service does not seem practical.Archaeo
It would only be persisted based on that session. I recommend looking at the data privacy docs for opting-in: docs.fabric.io/android/crashlytics/…Pelerine
P
35

according to mike answer, im add my code:

Gradle:

buildTypes {
   release {
        manifestPlaceholders = [crashlyticsEnabled: true]
    }

    debug {
        manifestPlaceholders = [crashlyticsEnabled: false]
    }
}

Manifest.xml:

<meta-data
    android:name="firebase_crashlytics_collection_enabled"
    android:value="${crashlyticsEnabled}" />
Phanotron answered 22/1, 2018 at 15:4 Comment(0)
P
23

Mike from Fabric here. Use:

<meta-data android:name="firebase_crashlytics_collection_enabled" android:value="false" />

if you want to disable Crashlytics while using Firebase.

Pelerine answered 23/10, 2017 at 15:20 Comment(8)
Thanks Mike! Is there any way to disable Crashlytics conditionally (outside the build type which the manifest is bound to)?I don't want Crashlytics reports for my "instrumented" buildType from developers' workstations, but I do want Crashlytics reports from the build server, so I check an environment variable in build.gradle to conditionally set enableCrashlytics to true / false.Ignite
@J.Williams: Would a manifestPlaceholder for the value of firebase_crashlytics_collection_enabled do what you need?Marbleize
@Mike is there a way to disable Crashlytics (while using Firebase) for iOS, too? Just for Debug-buildsGeneration
@Generation Take a look here: #28931822Pelerine
Hi, Mike! Would you please add this instruction on official site docs.fabric.io/android/crashlytics/… ?Breault
Thanks for the suggestion @nick_kryloff. We have it listed here: firebase.google.com/docs/crashlytics/… but I'll share the feedback with the team.Pelerine
Hi Mike, when I use this meta tag I understand I would have to call "Fabric.with(this, new Crashlytics())" to enable Crashlytics again. Would this then be enabled in a persistent way or would I need to call the code again when the app is restarted? I'm asking as crash reports should be optional for GDPR and calling this code in every activity/service does not seem practical.Archaeo
It would only be persisted based on that session. I recommend looking at the data privacy docs for opting-in: docs.fabric.io/android/crashlytics/…Pelerine
T
1

Along with mikes above answer,

If you are setting firebase crash properties somewhere in your code, make sure that you don't set them for debug code, otherwise you might notice strange behaviour for the app.

   if (!BuildConfig.DEBUG) {
       Crashlytics.setUserIdentifier(DataStore.storeId)
   }
Twohanded answered 10/5, 2019 at 11:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.