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

后端 未结 16 1397
谎友^
谎友^ 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:38

    First initialize variables in the gradle file and check whether it is in debug or in release mode. The best way to submit the crash report is within the Application class.

    Build.gradle

        buildTypes {
             release {
                 buildConfigField "Boolean", "REPORT_CRASH", '"true"'
                 debuggable false
             }
             debug {
                 buildConfigField "Boolean", "REPORT_CRASH", '"false"'
                 debuggable true
             }
        }
    

    Now first check the mode and submit the crash report if crashed .

    Application.java

        /** Report FirebaseCrash Exception if application crashed*/
        Thread.setDefaultUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler()
        {
            @Override
            public void uncaughtException (Thread thread, Throwable e)
            {
                /** Check whether it is development or release mode*/
                if(BuildConfig.REPORT_CRASH)
                {
                    FirebaseCrash.report( e);
                }
            }
        });
    

提交回复
热议问题