to top

lint

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.

For more information on running lint, see Improving Your Code with lint.

Syntax

lint [flags] <project directory>
For example, you can issue the following command to scan the Java and XML files under the myproject directory and its subdirectories. The result is displayed on the console.
lint myproject
You can also use lint to check for a specific issue. For example, you can run the following command to scan the files under the myproject directory and its subdirectories to check for XML attributes missing the Android namespace prefix. The issue ID MissingPrefix tells lint to only scan for this issue.
lint --check MissingPrefix myproject
You can create an HTML report for the issues that lint detects. For example, you can run the following command to scan the myproject directory and its subdirectories for accessibility issues, then generate an HTML report in the accessibility_report.html file.
lint --check Accessibility --HTML accessibility_report.html myproject

Options

Table 1 describes the command-line options for lint.

Table 1. Command-line options for lint

Category Option Description Comments
Checking --disable <list> Disable checking for a specific list of issues. The <list> must be a comma-separated list of lint issue IDs or categories.
--enable <list> Check for all the default issues supported by lint as well as the specifically enabled list of issues. The <list> must be a comma-separated list of lint issue IDs or categories.
--check <list> Check for a specific list of issues. The <list> must be a comma-separated list of lint issue IDs or categories.
-w or --nowarn Only check for errors and ignore warnings  
-Wall Check for all warnings, including those that are disabled by default  
-Werror Report all warnings as errors  
--config <filename> Use the specified configuration file to determine if issues are enabled or disabled for lint checking If the project contains a lint.xml file, the lint.xml file will be used as the configuration file by default.
Reporting --html <filename> Generate an HTML report. The report is saved in the output file specified in the argument. The HTML output includes code snippets of the source code where lint detected an issue, a verbose description of the issue found, and links to the source file.
--url <filepath>=<url> In the HTML output, replace a local path prefix <filepath> with a url prefix <url>. The --url option only applies when you are generating an HTML report with the --html option. You can specify multiple <filepath>=<url> mappings in the argument by separating each mapping with a comma.

To turn off linking to files, use --url none

--simplehtml <filename> Generate a simple HTML report The report is saved in the output file specified in the argument.
--xml <filename> Generate an XML report The report is saved in the output file specified in the argument.
--fullpath Show the full file paths in the lint checking results.  
--showall Don't truncate long messages or lists of alternate locations.  
--nolines Don't include code snippets from the source files in the output.  
--exitcode Set the exit code to 1 if errors are found.  
--quiet Don't show the progress indicator.  
Help --help List the command-line arguments supported by the lint tool. Use --help <topic> to see help information for a specific topic, such as "suppress".
--list List the ID and short description for issues that can be checked by lint  
--show List the ID and verbose description for issues that can be checked by lint Use --show <ids> to see descriptions for a specific list of lint issue IDs.
--version Show the lint version  

Configuring Java and XML Source Files

To configure lint checking, you can apply the following annotation or attribute to the source files in your Android project.

  • To disable lint checking for a specific Java class or method, use the @SuppressLint annotation.
  • To disable lint checking for specific sections of your XML file, use the tools:ignore attribute.

You can also specify your lint checking preferences for a specific Android project in the lint.xml file. For more information on configuring lint, see Improving Your Code with lint.