How to disable Firebase Crash Reporting when the app is running on debug?

I have successfully implemented Firebase Crash Reporting, but I need to disable the service when the app is running undo the 'debug' Build Variant, in order to avoid non-real crashes in the console during the development.

The official documentation doesn't say anything about this.


UPDATED: With Google Play Services / Firebase 11+ you could now disable crash reporting at runtime. FirebaseCrash.setCrashCollectionEnabled() (Thanks @Tyler Carberry)

OLD ANSWER:

There is no official support for this, as far as the community has been able to surmise. The best way I would suggest to do this is, set up multiple Firebase apps in your dashboard, one for each build type, and set up multiple google_services.json files directing to each different app depending on the build variant.


With Google Play Services 11.0 you could now disable crash reporting at runtime.

FirebaseCrash.setCrashCollectionEnabled(!BuildConfig.DEBUG);

Recently was introduced the possibility to disable Firebase crash reporting in a official way. You need to upgrade the firebase android sdk to at least version 11.0.0

In order to do so, you need to edit your AndroidManifest.xml and add:

<meta-data
   android:name="firebase_crashlytics_collection_enabled"
   android:value="false" />

Inside the <application> block.

You can check if Firebase crash report is enabled at runtime using FirebaseCrash.isCrashCollectionEnabled().

Below a complete example to disable Firebase crash reporting in your debug builds.

build.gradle:

...
 buildTypes {

    release {
        ...
        resValue("bool", "FIREBASE_CRASH_ENABLED", "true")
    }

    debug {
        ...
        resValue("bool", "FIREBASE_CRASH_ENABLED", "false")

    }

}
...
dependencies {
    ...
    compile "com.google.firebase:firebase-core:11.0.0"
    compile "com.google.firebase:firebase-crash:11.0.0"
    ...
}

AndroidManifest.xml:

 <application>

    <meta-data
        android:name="firebase_crash_collection_enabled"
        android:value="@bool/FIREBASE_CRASH_ENABLED"/>
...

in my Application class, onCreate()

if (BuildConfig.DEBUG) {
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
            Log.wtf("Alert", paramThrowable.getMessage(), paramThrowable);
            System.exit(2); //Prevents the service/app from freezing
        }
    });
}

It works because it takes the oldHandler, which includes the Firebase one

 final UncaughtExceptionHandler oldHandler = Thread.getDefaultUncaughtExceptionHandler();

out of the processing path