New Firebase Crashlytics disable in debug mode
Solution 1
I have tried once some time ago which worked for me . Add this to build.gradle
.
android {
buildTypes {
debug {
manifestPlaceholders = [crashlyticsCollectionEnabled:"false"]
...
}
release {
manifestPlaceholders = [crashlyticsCollectionEnabled:"true"]
...
}
}
}
And then set this attribute in manifest .
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="${crashlyticsCollectionEnabled}" />
If you log manually also then you can use something like this at runtime :-
FirebaseCrashlytics.getInstance().recordException(RuntimeException("Invalidtoken"))
Also Check this out .
Solution 2
To do it programmatically use below code in Application class
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG)
//enabled only for signed builds
Enable collection for select users by calling the Crashlytics data collection override at runtime. The override value persists across launches of your app so Crashlytics can automatically collect reports for future launches of that app instance. To opt out of automatic crash reporting, pass false as the override value. When set to false, the new value does not apply until the next run of the app.
Here is the link to documentation https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#enable-reporting
martin1337
Updated on June 06, 2022Comments
-
martin1337 about 2 years
I have recently switched to new Firebase Crashlytics from Fabric one and I can't find alternative for disabling Crashlytics in debug mode.
Fabric:
val crashlytics = Crashlytics.Builder().core(CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build() Fabric.with(this, crashlytics, Answers())
Anyone know answer? Ive seen that
FirebaseCrashlytics
class has its core set up internally now. I've triedFirebaseCrashlytics(CrashlyticsCore.??).getInstance()
, but that kind of constructor is not working.Also
CrashlyticsCore
class no longer has.Builder()
available -
wrozwad over 3 yearsMore safe way to add manifest placeholders in place of replace all of them will be:
manifestPlaceholders.firebasecrashlyticsCollectionEnabled = false
-
Vijay Desai over 3 yearsTo disable the crash logs while in debug mode you must pass
!BuildConfig.DEBUG
. Enabled only for signed buildsFirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG);
So the value will be false and it will only log crash for release build. -
Ananthakrishnan K R almost 3 yearsSince Crashlytics is enabled by default, I prefer this:
if (BuildConfig.DEBUG) { FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false) }
-
Tanjim ahmed almost 3 years@sosite can you please tell me in which tag i should add this line?
-
wrozwad almost 3 years@Tanjimahmed You use it directly in
debug
orrelease
build types -
Klemens Zleptnig over 2 years@wrozwad For the given example it should be
manifestPlaceholders. crashlyticsCollectionEnabled = false
- or alternativelymanifestPlaceholders["crashlyticsCollectionEnabled"] = false
.