68

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 tried FirebaseCrashlytics(CrashlyticsCore.??).getInstance(), but that kind of constructor is not working.

Also CrashlyticsCore class no longer has .Builder() available

3 Answers 3

93

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

Sign up to request clarification or add additional context in comments.

2 Comments

To disable the crash logs while in debug mode you must pass !BuildConfig.DEBUG. Enabled only for signed builds FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG); So the value will be false and it will only log crash for release build.
Since Crashlytics is enabled by default, I prefer this: if (BuildConfig.DEBUG) { FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false) }
80

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 and crashlytics opt-in.

4 Comments

More safe way to add manifest placeholders in place of replace all of them will be: manifestPlaceholders.firebasecrashlyticsCollectionEnabled = false
@sosite can you please tell me in which tag i should add this line?
@Tanjimahmed You use it directly in debug or release build types
@wrozwad For the given example it should be manifestPlaceholders. crashlyticsCollectionEnabled = false - or alternatively manifestPlaceholders["crashlyticsCollectionEnabled"] = false.
7

This works for me

manifest.xml
<meta-data android:name="firebase_crashlytics_collection_enabled" android:value="${crashlyticsCollectionEnabled}" /> 
build.gradle
buildTypes { release { manifestPlaceholders["crashlyticsCollectionEnabled"] = true } debug { manifestPlaceholders["crashlyticsCollectionEnabled"] = false } } 

check from official docs:

firebase and Inject build variables into the manifest

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.