简体   繁体   中英

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 .

I have moved all flavor specific resources inside the flavor specific res folder. 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

For testing the lint, I have introduced an unused resource inside the res folder of flavor1 and flavor2 . I tried to run ./gradlew lintFlavor1Release or ./gradlew lintFlavor2Release , its detecting the error and throwing respectively.

But ./gradlew lintRelease is not throwing any errors. Where am I going wrong?

Try something like this:

make a custom gradle task that will run all those lint tasks separately.

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.

and finally, you should be able to run it like ./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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM