Reputation: 1418
Is it possible to make Android Studio build fail on lint check errors ?
I have problems with ImageViews when I convert icon from .png to vector drawable .xml
Sometimes I forgot to change
android:src="@drawable/ic_minus"
to
app:srcCompat="@drawable/ic_minus"
and the app crashes on older OS devices.
?
Upvotes: 9
Views: 2658
Reputation: 1461
You can also use the below code inside android
block in module/app level build.gradle
file
For build.gradle
android {
applicationVariants.all {
// Example lint task, your verification task can be anything
def lintTask = tasks["lint${name.capitalize()}"]
assembleProvider.get().dependsOn(lintTask/*, detekt*/) // add list of all the tasks which should fail the build
}
}
For build.gradle.kts
(Kotlin DSL)
android {
applicationVariants.all {
// Example lint task, your verification task can be anything
val lintTask = tasks["lint${name.capitalize()}"]
assembleProvider.get().dependsOn.addAll(listOf(lintTask/*, tasks["detekt"]*/)) // add list of all the tasks which should fail the build
}
}
Above code makes the build assemble task which run when we run build app or run app, depends on the listed verification tasks and hence fails it when those tasks fails
Make sure your verification tasks(in our case lint
task) are set to fail the build when they are run and there are some issues found in them. All verification tasks has their own flags to enable this behaviour.
For lint you can enable the build failure on warning as below(build.gradle.kts
for Kotlin DSL)
android {
lint {
isWarningsAsErrors = true
}
}
Upvotes: 1
Reputation: 25413
If there's a lint check for that you can change the severity to FATAL
and then when building the release version of your APK it should fail.
android {
lintOptions {
fatal 'MY_LINT_CHECK_ID'
}
}
Also you can execute the Gradle lint
task which will fail. If you also want warnings to let your build fail you can use this.
android {
lintOptions {
warningsAsErrors true
}
}
Upvotes: 7