Home | History | Annotate | Download | only in help
      1 page.title=lint
      2 parent.title=Tools
      3 parent.link=index.html
      4 @jd:body
      5 
      6 <div id="qv-wrapper">
      7   <div id="qv">
      8      <h2>In this document</h2>
      9   <ol>
     10      <li><a href="#syntax">Syntax</a></li>
     11      <li><a href="#options">Options</a></li>
     12      <li><a href="#config_keywords">Configuring Java and XML Source Files</a></li>
     13   </ol>
     14   </div>
     15 </div>
     16 
     17 <p>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.</p>
     18 
     19 <p>In Android Studio, the configured <code>lint</code> and other IDE inspections run automatically
     20 whenever you compile your program. You can also manually run inspections in Android Studio
     21 by selecting <strong>Analyze &gt; Inspect Code</strong> from the application or right-click menu.
     22 The <em>Specify Inspections Scope</em> dialog appears so you can specify the desired inspection 
     23 profile and scope.</p>
     24 
     25 <p>For more information on enabling {@code lint} inspections and running {@code lint},
     26 see <a href="{@docRoot}tools/debugging/improving-w-lint.html">Improving Your Code with lint</a>.</p>
     27 
     28 <h2 id="syntax">Command Line Syntax</h2>
     29 <p>
     30 <pre>lint [flags] &lt;project directory&gt;</pre>
     31 
     32 For example, you can issue the following command to scan the Java and XML files under the
     33 {@code myproject}  directory and its subdirectories. The result is displayed on the console.
     34 <pre>lint myproject</pre>
     35 
     36 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.
     37 <pre>lint --check MissingPrefix myproject</pre>
     38 
     39 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.
     40 <pre>lint --check Accessibility --HTML accessibility_report.html myproject</pre>
     41 </p>
     42 
     43 <h2 id="options">Options</h2>
     44 <p>Table 1 describes the command-line options for {@code lint}.</p>
     45 <p class="table-caption" id="table1">
     46   <strong>Table 1.</strong> Command-line options for lint</p>
     47 <table>
     48 <tr>
     49   <th>Category</th>
     50   <th>Option</th>
     51   <th>Description</th>
     52   <th>Comments</th>
     53 </tr>
     54 
     55 <tr>
     56 <td rowspan="7">Checking</td>
     57 <td><nobr><code>--disable &lt;list&gt;</code></nobr></td>
     58 <td>Disable checking for a specific list of issues.</td>
     59 <td>The <code>&lt;list&gt;</code> must be a comma-separated list of {@code lint} issue IDs or categories.</td>
     60 </tr>
     61 
     62 <tr>
     63 <td><nobr><code>--enable &lt;list&gt;</code></nobr></td>
     64 <td>Check for all the default issues supported by {@code lint} as well as the specifically enabled list of issues.</td>
     65 <td>The <code>&lt;list&gt;</code> must be a comma-separated list of {@code lint} issue IDs or categories.</td>
     66 </tr>
     67 
     68 <tr>
     69 <td><nobr><code>--check &lt;list&gt;</code></nobr></td>
     70 <td>Check for a specific list of issues.</td>
     71 <td>The <code>&lt;list&gt;</code> must be a comma-separated list of {@code lint} issue IDs or categories.</td>
     72 </tr>
     73 
     74 <tr>
     75 <td><nobr><code>-w</code> or <code>--nowarn</code></nobr></td>
     76 <td>Only check for errors and ignore warnings</td>
     77 <td>&nbsp;</td>
     78 </tr>
     79 
     80 <tr>
     81 <td><nobr><code>-Wall</code></nobr></td>
     82 <td>Check for all warnings, including those that are disabled by default</td>
     83 <td>&nbsp;</td>
     84 </tr>
     85 
     86 <tr>
     87 <td><nobr><code>-Werror</code></nobr></td>
     88 <td>Report all warnings as errors</td>
     89 <td>&nbsp;</td>
     90 </tr>
     91 
     92 <tr>
     93 <td><nobr><code>--config &lt;filename&gt;</code></nobr></td>
     94 <td>Use the specified configuration file to determine if issues are enabled or disabled for {@code lint} checking</td>
     95 <td>If the project contains a {@code lint.xml} file, the {@code lint.xml} file will be used as the configuration file by default.</td>
     96 </tr>
     97 
     98 <tr>
     99 <td rowspan="9">Reporting</td>
    100 <td><nobr><code>--html &lt;filename&gt;</code></nobr></td>
    101 <td>Generate an HTML report.</td>
    102 <td>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.</td>
    103 </tr>
    104 
    105 <tr>
    106 <td><nobr><code>--url &lt;filepath&gt;=&lt;url&gt;</code></nobr></td>
    107 <td>In the HTML output, replace a local path prefix <code>&lt;filepath&gt;</code> with a url prefix <code>&lt;url&gt;</code>.</td>
    108 <td>The {@code --url} option only applies when you are generating an HTML report with the {@code --html} option. You can specify multiple &lt;filepath&gt;=&lt;url&gt; mappings in the argument by separating each mapping with a comma.<p>To turn off linking to files, use {@code --url none}</p></td>
    109 </tr>
    110 
    111 <tr>
    112 <td><nobr><code>--simplehtml &lt;filename&gt;</code></nobr></td>
    113 <td>Generate a simple HTML report</td>
    114 <td>The report is saved in the output file specified in the argument.</td>
    115 </tr>
    116 
    117 <tr>
    118 <td><nobr><code>--xml &lt;filename&gt;</code></nobr></td>
    119 <td>Generate an XML report</td>
    120 <td>The report is saved in the output file specified in the argument.</td>
    121 </tr>
    122 
    123 <tr>
    124 <td><nobr><code>--fullpath</code></nobr></td>
    125 <td>Show the full file paths in the {@code lint} checking results.</td>
    126 <td>&nbsp;</td>
    127 </tr>
    128 
    129 <tr>
    130 <td><nobr><code>--showall</code></nobr></td>
    131 <td>Don't truncate long messages or lists of alternate locations.</td>
    132 <td>&nbsp;</td>
    133 </tr>
    134 
    135 <tr>
    136 <td><nobr><code>--nolines</code></nobr></td>
    137 <td>Don't include code snippets from the source files in the output.</td>
    138 <td>&nbsp;</td>
    139 </tr>
    140 
    141 <tr>
    142 <td><nobr><code>--exitcode</code></nobr></td>
    143 <td>Set the exit code to 1 if errors are found.</td>
    144 <td>&nbsp;</td>
    145 </tr>
    146 
    147 <tr>
    148 <td><nobr><code>--quiet</code></nobr></td>
    149 <td>Don't show the progress indicator.</td>
    150 <td>&nbsp;</td>
    151 </tr>
    152 
    153 <tr>
    154 <td rowspan="4">Help</td>
    155 <td><nobr><code>--help</code></nobr></td>
    156 <td>List the command-line arguments supported by the {@code lint} tool.</td>
    157 <td>Use {@code --help &lt;topic&gt;} to see help information for a specific topic, such as "suppress".</td>
    158 </tr>
    159 
    160 <tr>
    161 <td><nobr><code>--list</code></nobr></td>
    162 <td>List the ID and short description for issues that can be checked by {@code lint}</td>
    163 <td>&nbsp;</td>
    164 </tr>
    165 
    166 <tr>
    167 <td><nobr><code>--show</code></nobr></td>
    168 <td>List the ID and verbose description for issues that can be checked by {@code lint}</td>
    169 <td>Use {@code --show &lt;ids&gt;} to see descriptions for a specific list of {@code lint} issue IDs.</td>
    170 </tr>
    171 
    172 <tr>
    173 <td><nobr><code>--version</code></nobr></td>
    174 <td>Show the {@code lint} version</td>
    175 <td>&nbsp;</td>
    176 </tr>
    177 
    178 </table>
    179 
    180 
    181 <h2 id="config_keywords">Configuring Java and XML Source Files</h2>
    182 <p>To configure lint checking, you can apply the following annotation or attribute to the source files in your Android project. </p>
    183 <ul>
    184 <LI>To disable {@code lint} checking for a specific Java class or method, use the <code>@SuppressLint</code>
    185 annotation. </LI>
    186 <li>To disable {@code lint} checking for specific sections of your XML file, use the
    187 <code>tools:ignore</code> attribute. </li>
    188 </ul>
    189 <p>You can also specify your {@code lint} checking preferences for a specific Android project in
    190 the <code>lint.xml</code> file.  For more information on configuring {@code lint}, see
    191 <a href="{@docRoot}tools/debugging/improving-w-lint.html">Improving Your Code with lint</a>.</p>
    192