I want to use different lint.xml files for release and debug build types in Android Studio. So, how can this be achieved?
When I place lint.xml in someModule/src/debug and someModule/src/release folders (also, these folders contain only that lint.xml file and nothing more) gradle reacts as there is no any lint.xml file, If I place single lint.xml file under core module folder (someModule/)- gradle recognizes it, but in this case I can't use different settings depending on build type...
The lint.xml fileA configuration file that you can use to specify any lint checks that you want to exclude and to customize problem severity levels.
A build type determines how an app is packaged. By default, the Android plug-in for Gradle supports two different types of builds: debug and release . Both can be configured inside the buildTypes block inside of the module build file.
Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.
With kotlin build scripts (build.gradle.kts
):
tasks.withType<LintBaseTask>().configureEach {
// doFirst is required else we get a Null Pointer Exception on lintOption
doFirst {
// This will override the lintOptions from the android extension
lintOptions.run {
if (name.toLowerCase().contains("debug")) {
// Do your configuration here
// isAbortOnError = true
// baselineFile = file("baseline.xml")
// isWarningsAsErrors = true
// isCheckDependencies = true
// ignore("MissingTranslation")
// setLintConfig(file("lint.xml"))
}
}
}
}
I did not try it, but maybe something like this could help you.
tasks.whenTaskAdded { task ->
if (task.name == 'lintDebug') {
task.ext.lintXmlFileName = "lint-debug.xml"
} else if (task.name == 'lintDemo') {
task.ext.lintXmlFileName = "lint-demo.xml"
}
}
EDIT: comments feedback:
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