Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create flavor specific Android Lint baseline file

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!

like image 233
Fabien Demangeat Avatar asked Sep 05 '25 03:09

Fabien Demangeat


2 Answers

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"
}
like image 157
himanshu saluja Avatar answered Sep 07 '25 21:09

himanshu saluja


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
}
like image 34
PKDev Avatar answered Sep 07 '25 23:09

PKDev