首页 > 解决方案 > 如何仅在发布版本中使用此构建工具(容易出错)?

问题描述

我在构建中使用了一个名为“errorprone”的代码分析工具。它适用于每种发布类型,但我只想将它用于发布版本(或更具体地说,非调试版本)。我的 gradle 配置的相关部分如下所示:

plugins {
    id "net.ltgt.errorprone" version "0.0.14"
}

...

tasks.withType(JavaCompile) {
    options.compilerArgs += [
            '-Xep:DefaultCharset:OFF',
}

...

dependencies {
    errorprone 'com.google.errorprone:error_prone_core:2.3.1'
}

我已经buildTypesdebug和进行了配置release。如何将容易出错的依赖项配置为仅使用release

标签: gradleandroid-gradle-pluginerrorprone

解决方案


Barry, Add your dependency as 

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
android.productFlavors.each {
        flavor ->
            if (flavor.name.contains("debug")) {
                implementation 'com.google.android.exoplayer:exoplayer:2.8.4'
                // add("ReleaseImplementation", ('com.android.support:leanback-v17:' + supportLibraryVersion))
                //add("${flavor.name}DebugImplementation", (fileTree(include: 'vgdrm.jar', dir: "${vgdrmRootDir}/${flavor.ext.vgdrmVersion}-debug")))
            }
    }

推荐阅读