简体   繁体   中英

Disable Crashlytics in Android library project for debug

I have a project with multiple modules. The common code of the modules is in a library module. The problem is that we added recently Crashlytics to our project (in the library module), and we keep receiving error reports even when we are in Debug mode.

I searched on the internet and I found out that a library is always seen as a Release mode. Now my question is, is there a way to disable Crashlytics in my case?

In my app (a single module, multiple flavors), I detect the flavor, and only initialize Crashlytics in the flavors that I want.

In my case, I add a variable to the flavor in build.gradle , like so:

productFlavors {
        Dev { // i.e. gradlew assembleDevDebug
            buildConfigField 'Boolean', 'enableCrashlytics', 'false'
        }

        Qa { // i.e. gradlew assembleQaDebug
            buildConfigField 'Boolean', 'enableCrashlytics', 'true'
        }
}

Then, in my Application class, I conditionally start Crashlytics:

if(BuildConfig.enableCrashlytics == true) {
   Fabric.with(this, new Crashlytics());
}

Assuming you enable Crashlytics/Fabric from your main module (which is recognised as being in debug), just conditionally initialise it so it does not activate in Debug mode.

eg

if (!BuildConfig.DEBUG) {
    Fabric.with(this, new Crashlytics()); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM