Fabric's Crashlytics with Firebase can't be disabled for DEBUG builds
Asked Answered
A

7

44

I have an app that utilises Fabric's Crashlytics via Firebase. The following is the first thing executed in my Applications onCreate

CrashlyticsCore crashlyticsCore = new CrashlyticsCore.Builder()
    .disabled(BuildConfig.DEBUG)
    .build();
Fabric.with(this, new Crashlytics.Builder().core(crashlyticsCore).build());

Nonetheless, the crashes are submitted in DEBUG == true mode.

I use the following versions

in my build.gradle classpath "io.fabric.tools:gradle:1.25.1"

in my app/build.gradle implementation "com.crashlytics.sdk.android:crashlytics:2.9.1"

Unfortunately the crashes still get reported. Any ideas, what I am doing wrong?

Appendant answered 28/3, 2018 at 7:44 Comment(2)
https://mcmap.net/q/264891/-how-to-disable-firebase-crash-reporting-when-the-app-is-running-on-debugLoveinamist
Thanks, but I am not using firebase-crash as it is deprecated now. Your proposed answer uses that. I am using crashlytics, it is just connected with the firebase console.Appendant
D
44

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.

Donettedoney answered 29/3, 2018 at 1:58 Comment(5)
Thanks, I'll try again.Appendant
It was a few issues that together led to the problem. Your answer helped me resolve them, so I am accepting it. Thank you!Appendant
I have the same problem myself and this solution does not seem to be enough. I have added the meta-data, I do NOT have "CrashlyticsInitProvider initialization successful" in the logs, I have quadruple checked that Fabric.with(this, new Crashlytics()); is only called on non-debug builds, I have version 2.9.3 of the SDK, and I am still getting crash reports. Please help - if there is nothing else to do I'll try the gradle-based solution mentioned below.Inhibit
I tried this, does not seem to work anymore, unfortunately. CrashlyticsInitProvider: CrashlyticsInitProvider initialization successful doesn't show in the logs in DEBUG builds anymore, but crashes are still sent to my Console. firebase_core_version = '16.0.5' & firebase_crashlytics_version = '2.9.6'Chapell
as of the latest Crashlytics it prints out I/CrashlyticsCore: Initializing Crashlytics 2.6.6.29Signac
M
133

Correct answers have been posted by Bob Snyder and niqueco already however it seems kinda tedious to change the meta-data value every time you are building an actual release APK thus here's a solution that uses so called manifestPlaceholder and changes the value automatically to trueor false depending on the buildType.

Add the following to your apps build.gradle

android {

    // ...

    buildTypes {
        debug {
            manifestPlaceholders = [enableCrashReporting:"false"]
        }
        release {
            manifestPlaceholders = [enableCrashReporting:"true"]
        }
    }

}

And this to your AndroidManifest.xml

<manifest ... >

    <application ...>

        // ...

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

    </application>

</manifest>

You can verify the current value by clicking on the Merged Manifest tab once you have opened the AndroidManifest.xml. You should see something like this:

Merged manifest meta-data value for crash reporting

Mainly answered 2/9, 2018 at 10:9 Comment(4)
It links the other answers that explain the reasoning AND it also provides a clean SOLUTION.Bisulcate
Best and more generic approach. Thanks :)Chronon
Yes, that is exactly how I do it. I upvoted your answer. However, I leave the accepted answer as is, because it pointed me to the correct solution.Appendant
Thats some nice solution!Parabola
D
44

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.

Donettedoney answered 29/3, 2018 at 1:58 Comment(5)
Thanks, I'll try again.Appendant
It was a few issues that together led to the problem. Your answer helped me resolve them, so I am accepting it. Thank you!Appendant
I have the same problem myself and this solution does not seem to be enough. I have added the meta-data, I do NOT have "CrashlyticsInitProvider initialization successful" in the logs, I have quadruple checked that Fabric.with(this, new Crashlytics()); is only called on non-debug builds, I have version 2.9.3 of the SDK, and I am still getting crash reports. Please help - if there is nothing else to do I'll try the gradle-based solution mentioned below.Inhibit
I tried this, does not seem to work anymore, unfortunately. CrashlyticsInitProvider: CrashlyticsInitProvider initialization successful doesn't show in the logs in DEBUG builds anymore, but crashes are still sent to my Console. firebase_core_version = '16.0.5' & firebase_crashlytics_version = '2.9.6'Chapell
as of the latest Crashlytics it prints out I/CrashlyticsCore: Initializing Crashlytics 2.6.6.29Signac
M
9

I've finally found the issue. Crashlytics is initialized from a content provider, so by the time you try to disable from Application's onCreate() it's too late. Going through the decompiled code I've seen that you can disable that initialization by adding metadata to the <application> element in the manifest.

So, what I do is this... I've added this to app/src/debug/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?><!--suppress ALL -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="<your app package>">

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

</manifest>

I've also disabled Crashlytics in the app module gradle build file by adding:

    debug {
        ext.enableCrashlytics = false
    }

To my surprise I didn't need to do the Fabric.with(...) thing. The above was enough.

It's working fine: no reports.

Milo answered 29/3, 2018 at 3:2 Comment(3)
Thanks, I'll try again.Appendant
ext.enableCrashlytics = false This line is crashing my app with below message - "This app relies on Crashlytics. Please sign up for access at fabric.io/sign_up,"Dost
@AjithMemana This is working for old Fabric Crashlytics. Not Fabric's Crashlytics with Firebase that is the question is about it. For that look at the accepted answerSentimentalize
K
5

I think it is possible to do it from code as well if you switched to firebase crashlytics and removed fabric crashlytics : link to firebase doc

So in the onCreate of your application class :

FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG);
Kenning answered 10/4, 2020 at 14:8 Comment(1)
Unable to see the crashes for dev. How can I enable the crashesWildermuth
C
3

Got this information from android documentation Customize your Firebase Crash Reports

Enable opt-in reporting: By default, Firebase Crashlytics automatically collects crash reports for all your app's users. To give users more control over the data they send, you can enable opt-in reporting instead.

To do that, you have to disable automatic collection and initialize Crashlytics only for opt-in users.

Turn off automatic collection with a meta-data tag in your AndroidManifest.xml file:

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

Enable collection for selected users by initializing Crashlytics from one of your app's activities:

Fabric.with(this, new Crashlytics());
Cocteau answered 17/12, 2018 at 6:56 Comment(0)
L
2

You need to disable Crashlytics of app’s build.gradle. Disable Crashlytics for Debug Builds

android {
    buildTypes {
        debug {
          // Disable fabric build ID generation for debug builds
          ext.enableCrashlytics = false
          ...  
Loveinamist answered 28/3, 2018 at 9:16 Comment(7)
Thanks again, but I need to do it at runtime for a couple of reasons. Any idea why .disabled is not working? It is working perfectly in other apps, where I do not have Firebase connected. It seems to be a firebase Bug, no?Appendant
You need to do ext.enableCrashlytics = false in your gradle and CrashlyticsCore crashlyticsCore = new CrashlyticsCore.Builder() .disabled(BuildConfig.DEBUG) .build(); Fabric.with(this, new Crashlytics.Builder().core(crashlyticsCore).build()); in your application classLoveinamist
Unfortunately, nope. It still deployes the crashes produced in debug mode. I also tried disabling it in the manifest with firebase_crashlytics_collection_enabledAppendant
@Appendant Did you finally found a solution that worked for you?Mccarter
@Shobhit Puri yes. Take a look at the accepted answerAppendant
Thanks @peshkira. I went through that. However I had to make an additional check for if (!BuildConfig.DEGUG) {Fabric.with()}. I initially thought from docs that just the manifest entry is enough.Mccarter
This is working for old Fabric Crashlytics. Not Fabric's Crashlytics with Firebase that is the question is about it.Sentimentalize
M
1

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 follow @reVerse's answer but 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>

Maneater answered 20/7, 2019 at 4:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.