Laura
Laura

Reputation: 2803

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?

Upvotes: 3

Views: 3762

Answers (2)

GreyBeardedGeek
GreyBeardedGeek

Reputation: 30088

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());
}

Upvotes: 12

Kuffs
Kuffs

Reputation: 35651

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()); 
}

Upvotes: 6

Related Questions