21

When using Crashlytics + Fabric for Android there is a really easy way to enable and disable crash reporting. I use it so during development and testing there aren't a ton of crashes alerting everyone.

Crashlytics crashlytics = new Crashlytics.Builder().disabled(true).build();

The disabled(boolean) method is now deprecated. Does anyone know what the replacement is for disabling and enabling crashlytics programmatically?

Cameron McBride
  • 6,779
  • 11
  • 40
  • 52

2 Answers2

60

Mike from Crashlytics and Fabric here.

Here's what you want to use depending on your preference:

CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
Fabric.with(this, new Crashlytics.Builder().core(core).build());

or

Fabric.with(this, new Crashlytics.Builder().core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build());

See CrashlyticsCore.Builder#disabled documentation.

arekolek
  • 9,128
  • 3
  • 58
  • 79
Mike Bonnell
  • 16,181
  • 3
  • 61
  • 77
  • 3
    Perfect! I wish there was better documentation where I could have found this. – Cameron McBride May 27 '15 at 20:07
  • Mike , does the second line have to read this way: Fabric.with(this, new Crashlytics.Builder().core(core).build(), new Crashlytics()); If not then I keep receiving the following error in the stacktrace when the app launches E/Fabric﹕ Error performing auto configuration. java.util.concurrent.ExecutionException: java.lang.IncompatibleClassChangeError: interface not implemented – joelreeves May 28 '15 at 22:08
  • @jmrmb80 try using Crashytics 2.3.0 and let me know if that works! – Mike Bonnell May 29 '15 at 13:54
  • @Mike B Thanks that fixed it! – joelreeves May 30 '15 at 10:15
  • 1
    The Android Studio plugin keeps correcting it? Fabric.with(this, new Crashlytics.Builder().core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build()); >> Fabric.with(this, new Crashlytics.Builder().core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build(), new Crashlytics()); – TomCB Jun 12 '15 at 14:14
  • 1
    Is this redundant if we disable crashlytics in gradle via [the documentation](http://support.crashlytics.com/knowledgebase/articles/202938-gradle) that suggests adding `ext.enableCrashlytics = false` to the flavor? – gMale Jul 16 '15 at 20:56
  • 3
    @gmale that command disables Crashlytics from being built as part of your Gradle build flow. It doesn't disable Crashlytics at run time. See my answer here: http://stackoverflow.com/questions/28339323/disable-importing-of-crashlytics/28357998#28357998 – Mike Bonnell Jul 17 '15 at 12:37
  • @MikeB how can we disable it at runtime? – Shajeel Afzal Aug 23 '15 at 16:06
  • Above code is not working, i am using `com.crashlytics.sdk.android:crashlytics:2.3.2@aar` – Shajeel Afzal Aug 23 '15 at 16:07
  • @ShajeelAfzal you'd want to use something like this: http://stackoverflow.com/questions/31992076/disable-crashlytics-answers-based-on-user-setting – Mike Bonnell Aug 31 '15 at 18:30
  • @MikeBonnell, will this code disable it if it has already been enabled before? From what I see, 'Fabric.with()' returns a singleton that doesn't change if it has already been initialized. – Héctor Júdez Sapena Feb 08 '16 at 15:46
  • @HéctorJúdezSapena There isn't a "kill" switch for the SDK currently. Once enabled, Crashlytics continues to run until a session ends. You would need to restart the app to disable it once more. – Mike Bonnell Feb 09 '16 at 15:40
  • @MikeBonnell i did what you mentioned above. But I think its not working. I am still getting `Crashlytics report upload complete: .cls` – Udayaditya Barua Jun 02 '16 at 09:12
  • @uday There have been many different comments, so it's a bit hard to follow along. Can you share more information about what you're using and what's not working? – Mike Bonnell Jun 02 '16 at 17:20
  • This is still sending crash reports on debug builds. Marc's answer might be convenient for this case but the project i am working on previous developer used crashlytics.logException method in a lot of places. I wish disabled method actually stop sending crash reports on debug builds. – Fatih Santalu Dec 29 '17 at 13:57
  • @MikeBonnell There isn't a "kill" switch for the SDK currently. Once enabled, Crashlytics continues to run until a session ends. You would need to restart the app to disable it once more. Its an older comment, Is this Statement valid even now ? We can't Disable Fabric , if it is already enabled in a single session ? – Sasank Sunkavalli Apr 16 '18 at 10:15
  • Correct, there have been no changes to the SDK on this. – Mike Bonnell Apr 16 '18 at 20:48
1

The Fabric Crashlytics SDK is now deprecated and FirebaseCrashlytics should be used

// Explicit initialization of Crashlytics is no longer required.
// OPTIONAL: If crash reporting has been explicitly disabled previously, add:
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG);

See the migration documentation here

Ben Russell
  • 61
  • 1
  • 4