简体   繁体   English

如何在一个命令中为所有产品风格运行 lint - Android?

[英]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 同步之后,已经生成了三种不同的风格,比如flavor1Debugflavor1Releaseflavor2Debugflavor2Release

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 (应该为flavor1Releaseflavor2Release运行 lint )时,它没有检测到任何错误

For testing the lint, I have introduced an unused resource inside the res folder of flavor1 and flavor2 .为了测试 lint,我在flavor1flavor2res文件夹中引入了一个未使用的资源。 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.

相关问题 对主要和特定风味运行单元测试 android - Run unit test for main and specific flavours android Android Studio和Favourites-无法查看所有文件 - Android studio and flavours - can not see all files 在 IntelliJ Java 应用程序中构建变体(产品风格) - Build variants (product flavours) in IntelliJ Java application Android Lint。 是否可以通过命令行扫描.java类 - Android Lint. Is it possible to scan .java classes via command line 如何以其他方式强制使用Android Studio`see`源,因此重构抽象类将更加安全 - How to force Android Studio `see` source in other flavours, so refactoring of abstract classes would be safer 针对不同口味的Android应用程序的动态应用程序流程 - Dynamic Application Flow for different flavours of Android application 如何在Android应用程序中运行终端命令? - How to run terminal command in Android application? 如何使用Playframework呈现特殊的XML / JSON Flavors - How to render special XML/JSON Flavours with Playframework 是否可以在Android lint报告中包含Javac lint? - Is it possible to include Javac lint in the Android lint report? Android:onRequestPermissionsResult棉绒警告 - Android: onRequestPermissionsResult lint warning
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM