Android Disable Crashlytics In Library Project For

2019-05-10 16:54发布

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?

Thanks

2条回答
2楼-- · 2019-05-10 17:49

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());
}
查看更多
家丑人穷心不美
3楼-- · 2019-05-10 17:51

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.

e.g

if (!BuildConfig.DEBUG) {
    Fabric.with(this, new Crashlytics()); 
}
查看更多
登录 后发表回答