有人能告诉我如何避免每次运行 gradle check 时都执行 "lint" 吗?
在 build.gradle 中我已经定义了:
lintOptions {
quiet true
}
然而,它仍在执行这项任务。问题是每次我需要检查时,它都需要花费很长时间。
check
任务时添加-x lint
来跳过它:./gradlew check -x lint
apply plugin: 'com.android.application'
之前在你的build.gradle
文件中添加以下内容:tasks.whenTaskAdded { task ->
if (task.name.equals("lint")) {
task.enabled = false
}
}
./gradlew check -x lint
了。 - Jose M Lechon在项目设置期间,我刚刚禁用了该任务:
android {
lintOptions {
tasks.lint.enabled = false
}
}
注意:不一定需要将该语句放在android.lintOptions
内,但是既然它正在配置lint,将它们放在一起会更好。
注意:不一定需要将该语句放在android.lintOptions
内,但是既然它正在配置lint,将它们放在一起会更好。
checkReleaseBuilds
设置为false
会禁用发布版本构建的代码检查。将以下脚本添加到您的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
}
对于想知道如何在多个子项目中执行此操作的任何人,我最终需要使用根项目build.gradle文件禁用它们,如下所示:
task lintCheck() {
getAllTasks(true).each {
def lintTasks = it.value.findAll { it.name.contains("lint") }
lintTasks.each {
it.enabled = false
}
}
}
tasks.withType(com.android.build.gradle.tasks.LintBaseTask).configureEach {
enabled = false
}
(已在Android Gradle插件3.3.2上测试过。)
afterEvaluate {
Set<Task> result = tasks.findAll { task -> task.name.startsWith('lintVital') }
result.each { Task task ->
task.enabled = false
}
}
-x lint
对于 com.android.tools.build:gradle:3.5.4
无效
你应该使用 -x lintVitalRelease -x lint -x lintVitalSourceSets
代替.
例如:
gradlew --stacktrace build -x lintVitalRelease -x lint -x lintVitalSourceSets
如果您仍希望lint任务正常工作,您也可以:
project.tasks.check.dependsOn.remove("lint")
lint-results-debug.txt
,只是禁用了实际上并不是代码中真正问题而更像是有限的lint错误的错误。就像这个例子:.../Users/renetik/Development/renetik-instruments-android/project/renetik-instruments-library/src/main/res/layout/controller_chord.xml:9: Error: No orientation specified, and the default is horizontal. This is a common source of bugs when children are added dynamically. [Orientation]...
所以我在 renetik-instruments-library 的模块构建 gradle 中添加了内容。
android {
...
lintOptions {
disable 'IncludeLayoutParam', 'Orientation', 'UseAppTint'
}
}
现在构建已经可以正常工作了...并且有用的代码检查仍然存在。
但是对于复杂项目的构建性能改进,这可能是一个奇迹:
afterEvaluate {
tasks.findAll { it.name.startsWith('lint') }.each { it.enabled = false }
}
但是你必须将其放置或包含在每个模块的 build.gradle 文件中,而不能在项目的 build.gradle 文件中使用。如果应用正确,您可以在构建输出控制台中看到以下内容:
Task :renetik-instruments-app:lintVitalAnalyzeDebug SKIPPED
。