page.title=lint parent.title=Tools parent.link=index.html @jd:body

In this document

  1. Syntax
  2. Options
  3. Configuring Java and XML Source Files

The Android {@code 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.

In Android Studio, the configured lint and other IDE inspections run automatically whenever you compile your program. You can also manually run inspections in Android Studio by selecting Analyze > Inspect Code from the application or right-click menu. The Specify Inspections Scope dialog appears so you can specify the desired inspection profile and scope.

For more information on enabling {@code lint} inspections and running {@code lint}, see Improving Your Code with lint.

Command Line Syntax

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

Options

Table 1 describes the command-line options for {@code 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 {@code lint} issue IDs or categories.
--enable <list> Check for all the default issues supported by {@code lint} as well as the specifically enabled list of issues. The <list> must be a comma-separated list of {@code lint} issue IDs or categories.
--check <list> Check for a specific list of issues. The <list> must be a comma-separated list of {@code 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 {@code lint} checking If the project contains a {@code lint.xml} file, the {@code 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 {@code 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 {@code --url} option only applies when you are generating an HTML report with the {@code --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 {@code --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 {@code 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 {@code lint} tool. Use {@code --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 {@code lint}  
--show List the ID and verbose description for issues that can be checked by {@code lint} Use {@code --show <ids>} to see descriptions for a specific list of {@code lint} issue IDs.
--version Show the {@code 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.

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