简体   繁体   English

在 Android 库项目中禁用 Crashlytics 进行调试

[英]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.问题是我们最近在我们的项目中添加了 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.在我的应用程序(单个模块,多种风格)中,我检测了风格,并且只在我想要的风格中初始化 Crashlytics。

In my case, I add a variable to the flavor in build.gradle , like so:就我而言,我在 build.gradle 中为风味添加了一个变量,如下所示:

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:然后,在我的 Application 类中,我有条件地启动 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.假设您从主模块(被识别为处于调试状态)启用 Crashlytics/Fabric,只需有条件地初始化它,使其不会在调试模式下激活。

eg例如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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