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:
<application
android:name="...>
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false" />
...
</application>
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");
}