Woogux Wu Woogux Wu - 10 months ago 50
Android Question

Customize Lint with Gradle

How to write a Gradle Lint check task? Can I run the task from command line and get the lint logs (not from Android Studio)?

For example: in Eclipse, the command may look like:

lint --check UnusedResources ~/myproject_path > lint_log.log

Then I can find log info in
. How could this work when I use gradle?


The lint command just executes Android´s Lint CLI (which is a sort of stand-alone-tool which comes with the Android SDK).

But the Android Gradle Plugin (the one you apply with apply plugin: 'com.android.application' in your project´s build.gradle) automatically adds certain lint tasks.

So there is no need to write own tasks. You can configure a lot of Lint related options with lintOptions. See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Lint-support.

To see all available lint tasks just call: ./gradlew -q tasks | grep lint

You will see that you have one dedicated task for each build variant.

-> lint will check all variants -> others tasks will most commonly be lintDebug or lintRelease