How to disable Firebase Crash Reporting when the app is running on debug?
Solution 1
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.
Solution 2
With Google Play Services 11.0 you could now disable crash reporting at runtime.
FirebaseCrash.setCrashCollectionEnabled(!BuildConfig.DEBUG);
Solution 3
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"/>
...
Solution 4
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
Solution 5
You can change the firebase crash dependency to a release only dependency.
To do this, you define it as a releaseCompile dependency
releaseCompile 'com.google.firebase:firebase-crash:9.4.0'
Now it will only be included in the release builds. If you have other custom build types that you want crash reporting for, you can add it to them to.
customBuildTypeCompile 'com.google.firebase:firebase-crash:9.4.0'
Related videos on Youtube
facundomr
Updated on November 22, 2020Comments
-
facundomr over 3 years
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.
-
James Parsons about 8 years
if (!development) { FirebaseCrash.report(e);}
-
facundomr about 8 yearsThanks, @James_Parsons, but I did not mean that. I need to disable automatic crash reporting, not just the manual calls to the API.
-
Ankit Mundada over 7 years
releaseCompile 'com.google.firebase:firebase-crash:9.8.0'
won't this work? it is supposed to add the dependency only for your release builds, hence while developing the library won't be added to the project, right? -
itzhar over 6 yearscheck this answer: stackoverflow.com/a/48384549/3166417
-
-
facundomr about 8 yearsOkay, this could be useful. How can I tweak the
google_services.json
file so it can depends on my current Build Variant? As far as I know, you can only define different files based on the build variant, if they are in theapp/src/{flavor}
, but this file is in theapp
directory root -
WoogieNoogie about 8 yearsYeah, you're exactly right, you just need to move things around. Create app/src/release directory and move the current google_services.json file into there, then put the new files that were generated for each app type into the other folders.
-
facundomr about 8 yearsThanks! The tweak was useful. Hope to see this feature soon in the Firebase SDK.
-
Doug Stevenson about 8 yearsHi, I'm with the Crash Reporting team. We are looking into providing a way for you to disable crash reporting programmatically. We also found that some developers in some parts of the world are not allowed to collect crashes for legal reasons, and they also need a way to disable crash reporting at runtime.
-
Alin almost 8 years@DougStevenson it has been quite a while since your comment and I don't seem to find any way of disabling the automatic crash reporting. Any way to do it at the moment?
-
Frank over 7 yearsfor more details on this answer, see: firebase.googleblog.com/2016/08/…
-
KasparTr over 7 yearsDoesn't FB crash reporting only track apps signed with the specified keystore SHA1 under FB - Project Settings? If so then you are using debug.keystore for debug verison and FB shouldn't track that? I have the same problem as you but don't understand why tracking occurs when signed with another keystore?
-
Bronx over 7 yearsfor the first part you can simply use BuildConfig.DEBUG
-
Joel over 7 yearsFYI, even using this method, it appears that Firebase saves up all the crashes in a database, and if you ever install a release version on your emulator (to test ProGuard, for instance), it will then upload ALL the saved crashes.
-
Colin White over 7 years@DougStevenson Has this been added since your last comment? If not, is there a ticket I can follow for updates?
-
Doug Stevenson over 7 years@ColinWhite Sorry, there is nothing available yet. If you follow Firebase on twitter (or me CodingDoug), you'll likely hear about any new stuff that way.
-
Tyler Carberry about 7 yearsWith Google Play Services 11.0 you could now disable crash reporting at runtime. FirebaseCrash.setCrashCollectionEnabled(!BuildConfig.DEBUG);
-
rraallvv over 6 yearsDoes the flag
firebase_crash_collection_enabled
work for version 9.2.1 of Firebase? -
evi over 6 years@rraallvv no, the feature was not yet available
-
Leon over 6 yearsThis is a great solution and is based on the documented mechanism for disabled Crashlytics. The manifest key is now 'firebase_crashlytics_collection_enabled' by the way.
-
evi over 6 years@Leon, sorry mate, you are wrong. This approach is an android standard de facto for enable/disable things in manifest, the fact that is similar to the approach used by Crashlytics documentation is totally random!
-
Alex Shevelev almost 6 yearsNot "firebase_crash_collection_enabled" but "firebase_crashlytics_collection_enabled" - from firebase.google.com/docs/crashlytics/customize-crash-reports
-
evi almost 6 years@AlexShevelev Firebase Crashlytics is a different product, here we refer to firebase crash reporting, now deprecated