As per https://developer.android.com/studio/write/lint.html#snapshot we can create a Lint warning baseline file. The problem is that I have multiple flavors, each having their own sourceSets. Some files are used in a single flavor.
When I generate the baseline file, it's always specific to a variant. Which means that it's invalid for the other variants, ie it will miss some existing issues.
I have tried putting the
lintOptions {
  baseline file("lint-baseline.xml")
}
in the build and flavor blocks, but it won't generate multiple baselines.
Has anyone managed to generate flavor specific lint baseline file? And if so how?
Thanks!
I was trying the same thing and found a way of doing it.This create diff file for release and debug.You can put your custom logic in getfileName
lintOptions {
        baseline file(getFileName())
        checkAllWarnings true
        warningsAsErrors true
        abortOnError true
    }
def getCurrentFlavor() {
    Gradle gradle = getGradle()
    String tskReqStr = gradle.getStartParameter().getTaskRequests().args.toString()
    println tskReqStr
    if (tskReqStr.contains("Debug")) {
        return "debug"
    } else {
        return "release"
    }
}
private String getFileName(String command) {
    return getCurrentFlavor() + "-lint-baseline.xml"
}
I couldn't make the above answer exactly work as I got errors when trying to define the method in the build.gradle file.
Using himanshu saluja's answer this is what worked for me.
My root project's gradle file has:
ext.getLintFileName = {
    Gradle gradle = getGradle()
    String taskReq = gradle.getStartParameter().getTaskRequests().args.toString()
    if(taskReq.contains("Debug")) {
        return "debug-lint-baseline.xml"
    } else {
        return "release-lint-baseline.xml"
    }
}
And the sub project's gradle file inside the android block uses the value like this:
 lintOptions {
    baseline file(rootProject.ext.getLintFileName)
    checkDependencies true
    abortOnError true
    absolutePaths false
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With