在Android库项目中禁用Crashlytics进行调试 [英] Disable Crashlytics in Android library project for debug

查看:92
本文介绍了在Android库项目中禁用Crashlytics进行调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个模块的项目。模块的通用代码在库模块中。问题是我们最近在项目中(库模块中)添加了Crashlytics,即使在调试模式下,我们仍会收到错误报告。

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.

我在在互联网上,我发现图书馆总是被视为发布模式。现在我的问题是,有没有一种方法可以禁用Crashlytics?

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?

推荐答案

在我的应用程序中(单个模块,多个风味),我会检测到风味,然后仅在所需的风味中初始化Crashlytics。

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

在我的情况下,我在build.gradle中向风味添加了一个变量,像这样:

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'
        }
}

然后,在我的Application类中,我有条件地启动了Crashlytics:

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

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

这篇关于在Android库项目中禁用Crashlytics进行调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆