New Firebase Crashlytics disable in debug mode

18,119

Solution 1

I have tried once some time ago which worked for me . Add this to build.gradle.

android {
  buildTypes {
     debug {
        manifestPlaceholders = [crashlyticsCollectionEnabled:"false"]
        ...
     }

    release {
        manifestPlaceholders = [crashlyticsCollectionEnabled:"true"]
        ...
    }
  }
}

And then set this attribute in manifest .

<meta-data
        android:name="firebase_crashlytics_collection_enabled"
        android:value="${crashlyticsCollectionEnabled}" />

If you log manually also then you can use something like this at runtime :-

FirebaseCrashlytics.getInstance().recordException(RuntimeException("Invalidtoken"))

Also Check this out .

Solution 2

To do it programmatically use below code in Application class

FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG)
//enabled only for signed builds

Enable collection for select users by calling the Crashlytics data collection override at runtime. The override value persists across launches of your app so Crashlytics can automatically collect reports for future launches of that app instance. To opt out of automatic crash reporting, pass false as the override value. When set to false, the new value does not apply until the next run of the app.

Here is the link to documentation https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#enable-reporting

Share:
18,119
martin1337
Author by

martin1337

Updated on June 06, 2022

Comments

  • martin1337
    martin1337 about 2 years

    I have recently switched to new Firebase Crashlytics from Fabric one and I can't find alternative for disabling Crashlytics in debug mode.

    Fabric:

    val crashlytics = Crashlytics.Builder().core(CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build()
    Fabric.with(this, crashlytics, Answers())
    

    Anyone know answer? Ive seen that FirebaseCrashlytics class has its core set up internally now. I've tried FirebaseCrashlytics(CrashlyticsCore.??).getInstance(), but that kind of constructor is not working.

    Also CrashlyticsCore class no longer has .Builder() available

  • wrozwad
    wrozwad over 3 years
    More safe way to add manifest placeholders in place of replace all of them will be: manifestPlaceholders.firebasecrashlyticsCollectionEnabled = false
  • Vijay Desai
    Vijay Desai over 3 years
    To disable the crash logs while in debug mode you must pass !BuildConfig.DEBUG. Enabled only for signed builds FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEn‌​abled(!BuildConfig.D‌​EBUG); So the value will be false and it will only log crash for release build.
  • Ananthakrishnan K R
    Ananthakrishnan K R almost 3 years
    Since Crashlytics is enabled by default, I prefer this: if (BuildConfig.DEBUG) { FirebaseCrashlytics.getInstance().setCrashlyticsCollectionE‌​nabled(false) }
  • Tanjim ahmed
    Tanjim ahmed almost 3 years
    @sosite can you please tell me in which tag i should add this line?
  • wrozwad
    wrozwad almost 3 years
    @Tanjimahmed You use it directly in debug or release build types
  • Klemens Zleptnig
    Klemens Zleptnig over 2 years
    @wrozwad For the given example it should be manifestPlaceholders. crashlyticsCollectionEnabled = false - or alternatively manifestPlaceholders["crashlyticsCollectionEnabled"] = false.