How to disable Firebase Crash Reporting when the app is running on debug?

后端 未结 16 1294
谎友^
谎友^ 2020-12-04 13:42

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-r

相关标签:
16条回答
  • 2020-12-04 14:23

    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"/>
    ...
    
    0 讨论(0)
  • 2020-12-04 14:23

    Currently you can't disable firebase crash reporting although you can deactivate firebase analytics.

    So one way to do this is creating another app with different ID within same firebase project. After this you just need to change appID to enable or disable firebase crash reporting. I created below two app for my convenience:

    AppID:com.android - For release build type

    AppID:com.android.debug - For debug build type

    Please follow below link for more details:

    https://firebase.googleblog.com/2016/08/organizing-your-firebase-enabled-android-app-builds.html

    Edit: You don't need to change appID in android project again and again. There is a better way to use different appID for debug build type-

    android {
        defaultConfig {
            applicationId "com.android"
            ...
        }
        buildTypes {
            debug {
                applicationIdSuffix ".debug"
            }
        }
    }
    

    Checkout the link for more details:

    https://developer.android.com/studio/build/application-id.html

    Edit2:

    Basically in above solution you are making two different app in Firebase project, And this way you can separate your development and production errors.

    FYI Firebase crash reporting is deprecated. You should use Fabrics Crashlytics (Owned by Google). It has some really cool features.

    0 讨论(0)
  • 2020-12-04 14:24

    With Google Play Services 11.0 you could now disable crash reporting at runtime.

    FirebaseCrash.setCrashCollectionEnabled(!BuildConfig.DEBUG);
    
    0 讨论(0)
  • 2020-12-04 14:25

    For FirebaseAnalytics class.
    Disable collection: setAnalyticsCollectionEnabled(false);
    Enable collection: setAnalyticsCollectionEnabled(true); or write to AndroidManifest.xml in the application tag: <meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />

    Possible use:

    if (BuildConfig.DEBUG){ //disable for debug
        mFirebaseAnalytics.setAnalyticsCollectionEnabled(false);
    }
    

    Source

    0 讨论(0)
  • 2020-12-04 14:32

    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.

    0 讨论(0)
  • 2020-12-04 14:33

    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'
    
    0 讨论(0)
提交回复
热议问题