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
I found this to be the the easiest solution:
release {
...
buildConfigField 'Boolean', 'enableCrashlytics', 'true'
}
debug {
buildConfigField 'Boolean', 'enableCrashlytics', 'false'
}
The above lines will create a static boolean field called enableCrashlytics
in the BuildConfig
file which you can use to decide whether to initiate Fabric
or not:
if (BuildConfig.enableCrashlytics)
Fabric.with(this, new Crashlytics());
NOTE: With this method Fabrics is initialised only in release builds (as indicative in the above code). This means you need to put calls to statics methods in the Crashlytics
class in an if
block which checks whether Fabrics has been initialised as shown below.
if (Fabric.isInitialized())
Crashlytics.logException(e);
Otherwise the app will crash with Must Initialize Fabric before using singleton()
error when testing on the emulator.
We can use fabric's isDebuggable() method.
import static io.fabric.sdk.android.Fabric.isDebuggable;
if(! isDebuggable()){
// set Crashlytics ...
}
Happy coding :)
Step 1: In build.grade
buildTypes {
debug {
debuggable true
manifestPlaceholders = [enableCrashlytic:false]
}
release {
debuggable false
manifestPlaceholders = [enableCrashlytic:true]
}
}
Step 2: In manifest
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="${enableCrashlytic}" />
Step 3: In Application or first Activity
private void setupCrashReport() {
if (BuildConfig.DEBUG) return;
Fabric.with(this, new Crashlytics());
}
I am not sure if the step 3 is necessary, but to make sure the release version should work without crash. source: https://firebase.google.com/docs/crashlytics/customize-crash-reports#enable_opt-in_reporting
If you use Gradle just add this to a flavor:
ext.enableCrashlytics = false
Notice that you can also disable the annoying uploading of symbols in debug build:
def crashlyticsUploadStoredDeobsDebug = "crashlyticsUploadStoredDeobsDebug"
def crashlyticsUploadDeobsDebug = "crashlyticsUploadDeobsDebug"
tasks.whenTaskAdded { task ->
if (crashlyticsUploadStoredDeobsDebug.equals(task.name) ||
crashlyticsUploadDeobsDebug.equals(task.name)) {
println "Disabling $task.name."
task.enabled = false
}
}
Just put it into the build.gradle
of your application module.
The problem is that none of the solutions does work for the latest crashlytics sdk. (I'm using 2.9.0)
You can't disable it by code since it compiles into your project and runs before even a call onCreate of your application. So other solution is simple - don't compile crashlytics when not needed. Replace the 'compile' call with 'releaseCompile' within build.gradle file.
releaseCompile('com.crashlytics.sdk.android:crashlytics:2.9.0@aar') {
transitive = true
}