Once upon a time, particularly in Eclipse-land, Lint would run on every build, and so if you failed Lint checks, you would find out immediately. With Android Studio (tested
I accomplished this previously by adding a pre-push git hook that would run lint automatically on push, and fail to push if Lint errors were found. The pre-push hook script was stored in the Android project repo and was installed to a user's local machine automatically via gradle.
install-git-hooks.gradle
def hookDest = new File("${rootProject.rootDir}/.git/hooks/pre-push")
def prePushHook = new File("${rootProject.rootDir}/pre-push")
task installGitHooksTask(type: Copy) {
hookDest.delete()
hookDest << prePushHook.text
}
task gitExecutableHooks() {
Runtime.getRuntime().exec("chmod -R +x ${hookDest}");
println "gitExecutableHooks"
}
gitExecutableHooks.dependsOn installGitHooksTask
Than in your app build.gradle
apply from: rootProject.file('gradle/install-git-hooks.gradle')
pre-push
#!/bin/sh
#
# This hook is for Android project git repos.
#
# You can use git config variables to customize this hook.
# -----------------------------------------------------------
# Change hooks.lintTargetDirectory to point at a non . directory
# Change hooks.lintArgs to add any custom lint arguments you prefer
# Get custom info
dirToLint=$(git config hooks.lintTargetDirectory)
lintArgs=$(git config hooks.lintArgs)
projectDir=$(git rev-parse --show-toplevel)
lintReportPath="/app/lint-report.html"
# If user has not defined a preferred directory to lint against, make it .
if [ -z "$dirToLint"]
then
dirToLint="."
fi
# Perform lint check
echo "Performing pre-commit lint check of ""$dirToLint"
./gradlew lint
lintStatus=$?
if [ $lintStatus -ne 0 ]
then
echo "Lint failure, git push aborted."
echo "Open ${projectDir}${lintReportPath} in a browser to see Lint Report"
exit 1
fi
exit $lintStatus