How to disable Crashlytics during development

后端 未结 28 2604
心在旅途
心在旅途 2020-11-29 15:42

Is there any simple way to turn Crashlytics Android SDK off while developing ?

I don\'t want it to send a crash every time I do something stupid

On the othe

28条回答
  •  猫巷女王i
    2020-11-29 15:43

    2019 Answer

    I've been trying to only enable Crashlytics in release and disable in debug for 2 hours, checking the Firebase console to see if the Exceptions where uploaded or not.

    There are 2 possible ways to do this.

    OPTION 1

    It works, but if you call any Crashlytics method on debug builds the app will crash.

    app/build.gradle

    android {
        buildTypes {
            release {
                manifestPlaceholders = [crashlyticsEnabled: true]
            }
            debug {
                manifestPlaceholders = [crashlyticsEnabled: false]
            }
    

    AndroidManifest.xml

    
    

    OPTION 2

    An alternative if that allows you to call Crashlytics methods without checking BuildConfig.DEBUG first. With this setup you can safely call methods like Crashlytics.logException() - they simply do nothing in debug builds. I don't see the reports being uploaded in debug.

    app/build.gradle

    android {
        buildTypes {
            release {
                ext.enableCrashlytics = true
            }
            debug {
                ext.enableCrashlytics = false
            }
    

    AndroidManifest.xml

    
    

    Application onCreate()

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

提交回复
热议问题