9

I am developing an android app and have integrated the firebase and firebase crashlytics SDK.

I want to allow the user to disable crash reporting (to ensure GDPR compliance - I assume crash reports are related to GDPR) so need a way for the user to be able to disable it via the apps settings.

I found the docs at https://firebase.google.com/docs/crash/disable-sdk but when I try and the line:

FirebaseCrash.setCrashCollectionEnabled(true);

Android Studio gives me the error cannot resolve symbol 'FirebaseCrash'

This needs to be done programatically at runtime of the app.

Boardy
  • 35,417
  • 104
  • 256
  • 447

7 Answers7

19

In your module build gradle...

    release {
        //true value to send the crashlytics to the firebase
        manifestPlaceholders = [crashlyticsCollectionEnabled: "true"]
    }

    debug {
        //false value to stop sending the crashlytics to the firebase
        manifestPlaceholders = [crashlyticsCollectionEnabled: "false"]
    }

In the manifest

 <meta-data
       android:name="firebase_crashlytics_collection_enabled"
       android:value="${crashlyticsCollectionEnabled}" />
Abhishek Rana
  • 321
  • 2
  • 3
  • 1
    This worked for me (version 17.2.1). However, while disabled Crashlytics will STILL store crashes on the device. Whenever you enable again (assuming same device) it will flush out everything to the server anyway. Something to keep in mind if you are testing. – jj. Sep 04 '20 at 00:16
13

Disable Crashlytics at runtime

// Set up Crashlytics, disabled for debug builds
    Crashlytics crashlyticsKit = new Crashlytics.Builder()
    .core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
    .build();

    Fabric.with(this, crashlyticsKit);       

Ex

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set up Crashlytics, disabled for debug builds
    Crashlytics crashlyticsKit = new Crashlytics.Builder()
    .core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
    .build();

    Fabric.with(this, crashlyticsKit);
    setContentView(R.layout.activity_main);

}

More

boolean Agrees = value;
if(Agrees)
{
    Fabric.with(this,new Crashlytics());
}
else
 {
   CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(true).build();
   Fabric.with(this,  new Crashlytics.Builder().core(core).build());

throw new RuntimeException("why doesn't this show up in Firebase Crashlytics?");
 }

Edit 2

Ref : Fabric's Crashlytics with Firebase can't be disabled for DEBUG builds

The Firebase Crashlytics documentation explains that once reporting is enabled in an app session, it cannot be disabled.

By default, Crashlytics reporting is enabled in a ContentProvider named CrashlyticsInitProvider that executes before your Application instance is created. CrashlyticsInitProvider enables or disables reporting based on the meta-data value firebase_crashlytics_collection_enabled, which by default is true.

If you want reporting disabled, it's critical that the manifest meta-data be present and set to false:

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

Look in the logcat during app initialization for the message:

CrashlyticsInitProvider: CrashlyticsInitProvider initialization successful

If the message is present, firebase_crashlytics_collection_enabled is true. If the message is not present, you have successfully set the meta-data to disable crash reporting.

If the meta-data is missing or set to true, you cannot disable reporting in your code using a call to Fabric.with(...).

In a comment to another answer, you indicate that you tried disabling reporting using the meta-data and were not successful. Check for a typo and ensure the declaration is correctly placed in the <application> element. In my tests, I am able to disabling reporting using the meta-data and then enable at run time.

Ashvin solanki
  • 4,802
  • 3
  • 25
  • 65
  • 1
    Thanks that's what I was after, you'd think Google would be able to point their searches away from outdated documentation of their products – Boardy Aug 28 '18 at 20:05
  • Sorry, it is working I made a mistake. I used the meta-data name from [Firebase docs](https://firebase.google.com/docs/crash/disable-sdk) (it was "firebase_crash_collection_enabled") and didn't notice that the name in your example is different. – TimSim Mar 23 '19 at 09:29
  • 2
    Your comment about ensuring it is in the block was spot on. FWIW: output now confiirmes that it was skipped with the following message in logs: `CrashlyticsInitProvider: CrashlyticsInitProvider skipping initialization` – John Michael Pirie Jun 03 '19 at 13:31
10

With the new Firebase Crashlytics SDK, To disable the crash reporting, you have to use this method : setCrashlyticsCollectionEnabled

if (BuildConfig.DEBUG) {
  FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false)
}
Anis MARZOUK
  • 266
  • 2
  • 9
  • I guess it should probably always be by default in the app: `FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG)` so that development crashes don't obfuscate the Crashes that happen on production – Maksymilian Wojczuk May 19 '20 at 20:10
  • 4
    This is what the doc says: > whether to enable automatic data collection. ***When set to `false`, the new value does not apply until the next run of the app***. If you want to disable data collection by default for all app runs, add the `firebase_crashlytics_collection_enabled` flag to your app's AndroidManifest.xml. – rdias002 Jun 10 '20 at 16:32
2

If you would like to completely disable Firebase Crash reporting AND also not have to add the

com.crashlytics.sdk.android:crashlytics:2.9.1

dependency, then:

Add this to your app's build.gradle:

android {

    // ...

    defaultConfig {
        manifestPlaceholders = [enableCrashReporting:"false"]
        ....
    }

}

and then also add this to your AndroidManifest.xml:

<application ...>

    // ...

    <meta-data 
            android:name="firebase_crashlytics_collection_enabled" 
            android:value="${enableCrashReporting}" />
    <meta-data
            android:name="firebase_analytics_collection_deactivated"
            android:value="true"/>
</application>

Phileo99
  • 5,581
  • 2
  • 46
  • 54
1

FirebaseCrash.setCrashCollectionEnabled(true); is no longer supported in new version of Firebase Crash which is called Crashlytics. For More https://firebase.google.com/docs/crash/

FirebaseCrash.setCrashCollectionEnabled(true);

is replaced by

Fabric.with(this, new Crashlytics());

Take a look https://firebase.google.com/docs/crashlytics/upgrade-from-crash-reporting#set_up_manual_initialization

Anisuzzaman Babla
  • 6,510
  • 7
  • 36
  • 53
1

With new Firebase Crashlytics beta replacing Fabric one:

FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false)
Slava Glushenkov
  • 1,378
  • 1
  • 9
  • 10
1
  1. Disable automatic data collection (Manifest)
<meta-data android:name="firebase_crashlytics_collection_enabled" android:value="false" />
  1. Enable it if not debug build on your Application.
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG)
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83