[英]How to run lint for all product flavours in one command - Android?
I have implemented the product flavors for my project.我已经为我的项目实施了产品风味。 I am building three new application in the same codebase.我正在同一个代码库中构建三个新应用程序。
After gradle sync, three different flavors have been generated, say flavor1Debug , flavor1Release , flavor2Debug , flavor2Release .在 gradle 同步之后,已经生成了三种不同的风格,比如flavor1Debug 、 flavor1Release 、 flavor2Debug 、 flavor2Release 。
I have moved all flavor specific resources inside the flavor specific res folder.我已将所有风味特定资源移动到风味特定 res 文件夹中。 When I tried to run ./gradlew lintRelease (which is supposed to run lint for flavor1Release and flavor2Release ), it's not detecting any of the errors当我尝试运行./gradlew lintRelease (应该为flavor1Release和flavor2Release运行 lint )时,它没有检测到任何错误
For testing the lint, I have introduced an unused resource inside the res folder of flavor1 and flavor2 .为了测试 lint,我在flavor1和flavor2的res文件夹中引入了一个未使用的资源。 I tried to run ./gradlew lintFlavor1Release or ./gradlew lintFlavor2Release , its detecting the error and throwing respectively.我尝试运行./gradlew lintFlavor1Release或./gradlew lintFlavor2Release ,它分别检测错误和抛出。
But ./gradlew lintRelease is not throwing any errors.但是./gradlew lintRelease没有抛出任何错误。 Where am I going wrong?我哪里错了?
Try something like this:尝试这样的事情:
make a custom gradle task that will run all those lint tasks separately.制作一个自定义 gradle 任务,该任务将分别运行所有这些 lint 任务。
tasks.register("runAllLinters")
afterEvaluate {
if ("lintFlavor1Release" in tasks.names) {
runAllLinters.dependsOn tasks.named("lintFlavor1Release")
}
}
of course, this will trigger only for Flavor1 - so you will need to expand both the if()
condition, and the runAllLinters.dependsOn
block to depend on ALL flavour-dependant lint tasks.当然,这只会触发 Flavor1 - 因此您需要扩展if()
条件和runAllLinters.dependsOn
块以依赖于所有依赖于风味的 lint 任务。
and finally, you should be able to run it like ./gradlew runAllLinters
最后,您应该能够像./gradlew runAllLinters
一样运行它
Try this:尝试这个:
afterEvaluate {
def LINT_TASK_NAME = "lint"
def lintTask = tasks.findByName(LINT_TASK_NAME)
tasks.findAll { task ->
task.name.startsWith(LINT_TASK_NAME) &&
task.name != LINT_TASK_NAME &&
// remove some standard lint subtasks
!task.name.startsWith("lintFix") &&
!task.name.startsWith("lintAnalyze")
}.each { task -> lintTask.dependsOn.add(task) }
}
This makes task 'lint' to depend on all the other "lintXxxx" tasks except some standard.这使得任务“lint”依赖于除某些标准之外的所有其他“lintXxxx”任务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.