Android gradle 执行检查时避免 lint

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21143556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:02:38  来源:igfitidea点击:

avoid lint when gradle execute check

androidgradlelint

提问by Jose M Lechon

could someone tell me a way to avoid executing "lint" each time I run in gradle check?

有人可以告诉我每次在 gradle check 中运行时避免执行“lint”的方法吗?

I've defined in build.gradle

我在 build.gradle 中定义

lintOptions { 

    quiet true 

}

However, it keeps doing this task. The problem is that it takes ages each time I have to do a check.

但是,它一直在执行此任务。问题是每次我必须做检查都需要很长时间。

回答by kukido

回答by rciovati

You can skip it using adding -x lintwhen you run the checktask:

您可以-x lint在运行check任务时使用添加跳过它:

./gradlew check -x lint 

If you want to skip it permanently you can add this to your build.gradlebefore apply plugin: 'com.android.application':

如果您想永久跳过它,您可以将其添加到您的build.gradlebefore 中apply plugin: 'com.android.application'

tasks.whenTaskAdded { task ->
    if (task.name.equals("lint")) {
        task.enabled = false
    }
}

回答by TWiStErRob

I just disabled the task during project setup:

我只是在项目设置期间禁用了该任务:

android {
    lintOptions {
        tasks.lint.enabled = false
    }
}

Note: it's not necessary to put the statement inside android.lintOptions, but since it's configuring lint, it's nice to have them together.

注意:没有必要把语句放在里面android.lintOptions,但是因为它正在配置 lint,所以把它们放在一起很好。

回答by codezjx

Set checkReleaseBuildsto falsewill disable lint check on release build. Add following scripts to your build.gradle file:

设置checkReleaseBuildsfalse将禁用发布版本的 lint 检查。将以下脚本添加到您的 build.gradle 文件中:

lintOptions {
     /**
     * Set whether lint should check for fatal errors during release builds. Default is true.
     * If issues with severity "fatal" are found, the release build is aborted.
     */
    checkReleaseBuilds false
}

回答by Zenel

(Gradle 1.1.0, as packaged with Android Studio 1.1.0)

(Gradle 1.1.0,与 Android Studio 1.1.0 一起打包)

For anyone wondering how to do this with multiple subprojects, I ended up having to disable them using the root project build.gradle file like so:

对于想知道如何使用多个子项目执行此操作的任何人,我最终不得不使用根项目 build.gradle 文件禁用它们,如下所示:

task lintCheck() {
    getAllTasks(true).each {
        def lintTasks = it.value.findAll { it.name.contains("lint") }
        lintTasks.each {
            it.enabled = false
        }
    }
}

回答by Lanchon

use this code to disable all lint tasks using Gradle's new configuration avoidance API:

使用此代码通过 Gradle 的新配置避免 API 禁用所有 lint 任务:

tasks.withType(com.android.build.gradle.tasks.LintBaseTask).configureEach {
    enabled = false
}

(tested on Android Gradle plugin 3.3.2.)

(在 Android Gradle 插件 3.3.2 上测试。)

回答by Yu Han

If you still want the lint task to work you can also:

如果您仍然希望 lint 任务正常工作,您还可以:

project.tasks.check.dependsOn.remove("lint")

回答by Sebastiano

If you happen to have different build variants, perhaps a more robust script solution would be

如果您碰巧有不同的构建变体,也许更强大的脚本解决方案是

afterEvaluate {
  Set<Task> result = tasks.findAll { task -> task.name.startsWith('lintVital') }
  result.each { Task task ->
    task.enabled = false
  }
}