Android Lint Ignore specific errors

The Android lint tool is a static code analysis tool that checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization.


Running lint in command line

gradle lint

Running lint in Android Studio

To run lint in Android Studio go to Analyze > Inspect Code


Lint has a lot of option you can use in your build.gradle

lintOptions {
    // put your options here

See the complete options list in Gradle Plugin User Guide

To see the complete list of issues and categories id’s use:

lint --list

Ignoring Erros

Lint is part of Gradle build process, by default if it fail your build will stop and you will get a message like it:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.

In 99% of the cases people will start ignore lint instead of fix the problems, adding this on build.gradle app

lintOptions {   
    abortOnError false   

But IMHO it’s wrong. If lint is telling, you have a problem the best thing to do is fix it. Lint is a tools to make your app and the UX better.

Ignoring specific erros

Sometimes you really need to ignore some lint errors. For example, when you are using setJavaScriptEnabled(true); in your WebView

In this case, you should disable only the specific ids instead of disabling the whole lint.

lintOptions {
    disable 'SetJavaScriptEnabled'

You also can ignore it directly in your code:

@SuppressLint "SetJavaScriptEnabled")

Or in your XML

    tools:ignore="SomeLintIssueIdHere" >

If you prefer you can move all your issues rules from a lint.xml file in the root directory of your project.

<?xml version="1.0" encoding="UTF-8"?>
    <issue id="SetJavaScriptEnabled" severity="ignore" />

Add comment

By Daniel Passos