How to disable Crashlytics during development

后端 未结 28 2566
心在旅途
心在旅途 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条回答
  •  渐次进展
    2020-11-29 15:43

    The chosen answer is not correct any more. Google changed the integration of Crashlytics. My current version is 2.9.1 and the only thing I had to do is, to add implementation 'com.crashlytics.sdk.android:crashlytics:2.9.1' to my Gradle file. No further things required, nice but this means that Crashlytics is always running.

    Solution 1

    Only compile Crashlytics in release version:

    dependencies {
       ...
       releaseImplementation 'com.crashlytics.sdk.android:crashlytics:2.9.1' // update version
    }
    

    Solution 2

    If you want to additionally configure Crashlytics then Solution 1 is not working, since the Crashlytics classes will not be found in Debug Builds. So change the Gradle implementation back to:

    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.1' // update version
    

    Then go to your Manifest and add the following meta-data tag inside the application tag:

    
    
    ...
    
    
    

    Add to your Launch-Activity (only one-time required, not every Activity)

    if (!BuildConfig.DEBUG) { // only enable bug tracking in release version
       Fabric.with(this, new Crashlytics());
    }
    

    This will only enable Crashlytics in release versions. Be careful, also check for BuildConfig.DEBUG when you then configure Crashlytics, E.g:

    if (!BuildConfig.DEBUG) {
       Crashlytics.setUserIdentifier("HASH_ID");
    }
    

提交回复
热议问题