Android Static Code Check-lint

Source: Internet
Author: User
<span id="Label3"></p> <blockquote> <blockquote> <p>Reference article:<br>Improving Your Code with lint<br>Lint<br>Use lint to enhance your code<br>About Android Lint</p> </blockquote> </blockquote>Gradle Lint<p><p><code>gradle</code><code>lint</code>, you can perform lint static code checks directly, but only if you have the <code>build.gradle</code> <code>lintOptions</code> option set:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs bash">android { <span class="hljs-number">23</span> <span class="hljs-string">"21.1.2"</span> lintOptions { <span class="hljs-literal">false</span> }</code></pre></pre><p><p>Then we execute it at the root of the project <code>gradle lint</code> :</p></p><pre class="prettyprint"><code class=" hljs asciidoc">Localhost:sunshine-version-2 wuxian$ Gradle Lint<span class="hljs-attribute"><span class="hljs-attribute">: App:prebuild</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:predebugbuild</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:checkdebugmanifest</span></span><span class="hljs-attribute"><span class="hljs-attribute">: App:prereleasebuild</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:preparecomandroidsupportappcompatv72102library</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:preparecomandroidsupportsupportv42102library</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:preparedebugdependencies</span></span><span class="hljs-attribute"><span class="hljs-attribute">: App:compiledebugaidl</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:compiledebugrenderscript</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:generatedebugbuildconfig</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:generatedebugassets</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:mergedebugassets</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:generatedebugresvalues</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:generatedebugresources</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:mergedebugresources</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:processdebugmanifest</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:processdebugresources</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:generatedebugsources</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:processdebugjavares</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:compiledebugjavawithjavac</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:compilelint</span></span><span class="hljs-attribute"><span class="hljs-attribute">: App:checkreleasemanifest</span></span><span class="hljs-attribute"><span class="hljs-attribute">: App:preparereleasedependencies</span></span><span class="hljs-attribute"><span class="hljs-attribute">: App:compilereleaseaidl</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:compilereleaserenderscript</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:generatereleasebuildconfig</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:generatereleaseassets</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:mergereleaseassets</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:generatereleaseresvalues</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:generatereleaseresources</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:mergereleaseresources</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:processreleasemanifest</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:processreleaseresources</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:generatereleasesources</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:processreleasejavares</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:compilereleasejavawithjavac</span></span>Up-to-date<span class="hljs-attribute"><span class="hljs-attribute">: App:lint</span></span>Ran Lint on variant release:58 issues Foundran lint on variant debug:58 issues foundwrote HTML report to File:/users/wux Ian/documents/sourcecode/self/sunshine-version-2/app/build/outputs/lint-results.htmlwrote XML Report to/users/ Wuxian/documents/sourcecode/self/sunshine-version-2/app/build/outputs/lint-results.xmlbuild SUCCESSFULTotal Time : 17.941 secsthis build could is faster, please consider using the Gradle Daemon:http://gradle.org/docs/2.4/userguide/gra Dle<span class="hljs-emphasis"><span class="hljs-emphasis">_daemon.html</span></span></code></pre><p><p><code>build/outputs/</code>a file will be generated in the directory <code>lint-result.html</code> and opened to read as Follows:</p></p><p><p>The report was done too Much.</p></p>Summarize<p><p>This approach is suitable for automated CI system acquisition Results.</p></p>Manual analysis<p><p></p></p><p><p>After parsing the code, the popup dialog box allows you to choose to analyze the entire project/single module/file Bulabula:</p></p><p><p></p></p><p><p>After clicking ok, Wait for a period of time after the analysis is complete, will automatically pop up the results window</p></p><p><p></p></p><p><p><br>Depending on the type of inspection, different menus can be divided into different problem points by clicking on the corresponding menu:</p></p><p><p></p></p><p><p>After clicking on the problem point, the details of the problem will appear, the file name, location, location of the problematic point in the file, and the description of the problem, as well as a workaround to ignore the problem, which may also show the Workaround.</p></p>Summarize<p><p>This method is suitable for developing self-examination!</p></p>Lint command line<p><p><code>lint</code>Tool is located under <code>sdk</code> the directory <code>tools</code> , if the command line execution lint cannot find the command, then you need to <code>lint</code> configure the root directory to the environment variable, after the configuration succeeds, the execution <code>lint</code> command output is as Follows:</p></p><pre class="prettyprint"><code class=" hljs vhdl"><span class="hljs-number"><span class="hljs-number"></span> -</span>demacbook-pro-<span class="hljs-number"><span class="hljs-number">5</span></span>: Tools wuxian$ lintusage:lint [flags] <project directories>flags:<span class="hljs-comment"><span class="hljs-comment">--help this message.</span></span><span class="hljs-comment"><span class="hljs-comment">--help <topic> Help on the given topic, such as "suppress".</span></span><span class="hljs-comment"><span class="hljs-comment">--list List the available issue ID ' s and exit.</span></span><span class="hljs-comment"><span class="hljs-comment">--version Output version information and Exit.</span></span><span class="hljs-comment"><span class="hljs-comment">--exitcode Set The exit code to 1 if errors is Found.</span></span><span class="hljs-comment"><span class="hljs-comment">--show List available issues along with full explanations.</span></span><span class="hljs-comment"><span class="hljs-comment">--show <ids> Show full explanations for the given list of issue</span></span>Id<span class="hljs-attribute"><span class="hljs-attribute">' s</span></span>. Enabled Checks:<span class="hljs-comment"><span class="hljs-comment">--disable <list> Disable the list of categories or specific issue</span></span>Id<span class="hljs-attribute"><span class="hljs-attribute">' s</span></span>. The list should be a comma-separated list<span class="hljs-keyword"><span class="hljs-keyword"></span> of</span>Issue ID<span class="hljs-attribute"><span class="hljs-attribute">' s</span></span> <span class="hljs-keyword"><span class="hljs-keyword">or</span></span>Categories.<span class="hljs-comment"><span class="hljs-comment">--enable <list> enable the specific list of Issues. This checks</span> all</span>The<span class="hljs-keyword"><span class="hljs-keyword">default</span></span>Issues plus the specifically enabled Issues. The list should be a comma-separated list<span class="hljs-keyword"><span class="hljs-keyword"></span> of</span>Issue ID<span class="hljs-attribute"><span class="hljs-attribute">' s</span></span> <span class="hljs-keyword"><span class="hljs-keyword">or</span></span>Categories.<span class="hljs-comment"><span class="hljs-comment">--check <list> Only check the specific list of Issues. </span>this would</span>Disable everything<span class="hljs-keyword"><span class="hljs-keyword"></span> and</span>Re-enable the given list<span class="hljs-keyword"><span class="hljs-keyword"></span> of</span>Issues. The list should be a comma-separated list<span class="hljs-keyword"><span class="hljs-keyword"></span> of</span>Issue ID<span class="hljs-attribute"><span class="hljs-attribute">' s</span></span> <span class="hljs-keyword"><span class="hljs-keyword">or</span></span>categories.-w,<span class="hljs-comment"><span class="hljs-comment">--nowarn only check for errors (ignore Warnings)</span></span>-wall Check<span class="hljs-keyword"><span class="hljs-keyword"></span> all</span>warnings, including those off by<span class="hljs-keyword"><span class="hljs-keyword">default</span></span>-werror Treat<span class="hljs-keyword"><span class="hljs-keyword"></span> all</span>Warnings as Errors<span class="hljs-comment"><span class="hljs-comment">--config <filename> Use the given configuration file to determine whether</span></span>Issues is enabled<span class="hljs-keyword"><span class="hljs-keyword">or</span></span>Disabled.<span class="hljs-keyword"><span class="hljs-keyword">If</span></span>A project contains a lint.xml<span class="hljs-keyword"><span class="hljs-keyword">file</span></span>,<span class="hljs-keyword"><span class="hljs-keyword"></span> then</span>This config<span class="hljs-keyword"><span class="hljs-keyword">file</span></span>Would be used as a fallback. Output Options:<span class="hljs-comment"><span class="hljs-comment">--quiet Don ' t show progress.</span></span><span class="hljs-comment">--fullpath use full paths in the <span class="hljs-comment">error Output.</span></span><span class="hljs-comment"><span class="hljs-comment">--showall do not truncate long messages, lists of alternate</span></span>locations, etc.<span class="hljs-comment"><span class="hljs-comment">--nolines do not include the source file lines with errors</span> in</span>The Output. By<span class="hljs-keyword"><span class="hljs-keyword">default</span></span>, the error output includes snippets<span class="hljs-keyword"><span class="hljs-keyword"></span> of</span>Source code<span class="hljs-keyword"><span class="hljs-keyword"></span> on</span>The line containing the error, but this flag turns it off.<span class="hljs-comment"><span class="hljs-comment">--html <filename> Create an HTML report instead. If The filename is a</span></span>Directory (<span class="hljs-keyword"><span class="hljs-keyword">or</span></span>A<span class="hljs-keyword"><span class="hljs-keyword">New</span></span>FileName without an extension), lint would create a separate<span class="hljs-keyword"><span class="hljs-keyword"></span> report</span> <span class="hljs-keyword"><span class="hljs-keyword"></span> for</span>Each scanned project.<span class="hljs-comment"><span class="hljs-comment">--url Filepath=url Add links to HTML report, replacing local path</span></span>Prefixes<span class="hljs-keyword"><span class="hljs-keyword"></span> with</span>URL Prefix. The mapping can be a comma-separated list<span class="hljs-keyword"><span class="hljs-keyword"></span> of</span>Path prefixes<span class="hljs-keyword"><span class="hljs-keyword"></span> to</span>Corresponding URL prefixes, such as c:\temp\proj1=http://buildserver/sources/temp/proj1.<span class="hljs-keyword"><span class="hljs-keyword"></span> to</span>Turn off linking<span class="hljs-keyword"><span class="hljs-keyword"></span> to</span>Files<span class="hljs-keyword"><span class="hljs-keyword"></span> use</span> <span class="hljs-comment"><span class="hljs-comment">--url None</span></span><span class="hljs-comment"><span class="hljs-comment">--simplehtml <filename> Create a simple HTML</span> report</span><span class="hljs-comment"><span class="hljs-comment">--xml <filename> Create an XML report Instead.</span></span>Project Options:<span class="hljs-comment"><span class="hljs-comment">--resources <dir> Add The given folder (or Path) as a resource</span></span>Directory<span class="hljs-keyword"><span class="hljs-keyword"></span> for</span>The Project. Only valid<span class="hljs-keyword"><span class="hljs-keyword"></span> when</span>Running Lint<span class="hljs-keyword"><span class="hljs-keyword"></span> on</span>A single Project.<span class="hljs-comment"><span class="hljs-comment">--sources <dir> Add The given folder (or Path) as a source directory</span></span> <span class="hljs-keyword"><span class="hljs-keyword"></span> for</span>The Project. Only valid<span class="hljs-keyword"><span class="hljs-keyword"></span> when</span>Running Lint<span class="hljs-keyword"><span class="hljs-keyword"></span> on</span>A single Project.<span class="hljs-comment"><span class="hljs-comment">--classpath <dir> Add The given folder (or jar file, or Path) as a</span></span>Class Directory<span class="hljs-keyword"><span class="hljs-keyword"></span> for</span>The Project. Only valid<span class="hljs-keyword"><span class="hljs-keyword"></span> when</span>Running Lint<span class="hljs-keyword"><span class="hljs-keyword"></span> on</span>A single Project.<span class="hljs-comment"><span class="hljs-comment">--libraries <dir> Add The given folder (or jar file, or Path) as a</span></span>Class<span class="hljs-keyword"><span class="hljs-keyword">Library</span></span> <span class="hljs-keyword"><span class="hljs-keyword"></span> for</span>The Project. Only valid<span class="hljs-keyword"><span class="hljs-keyword"></span> when</span>Running Lint<span class="hljs-keyword"><span class="hljs-keyword"></span> on</span>A single Project.<span class="hljs-keyword"><span class="hljs-keyword">Exit</span></span>Status:<span class="hljs-number"><span class="hljs-number">0</span></span>Success.<span class="hljs-number"><span class="hljs-number">1</span></span>Lint Errors Detected.<span class="hljs-number"><span class="hljs-number">2</span></span>Lint Usage.<span class="hljs-number"><span class="hljs-number">3</span></span>Cannot clobber existing<span class="hljs-keyword"><span class="hljs-keyword">file</span></span>.<span class="hljs-number"><span class="hljs-number">4</span></span>Lint Help.<span class="hljs-number"><span class="hljs-number">5</span></span>Invalid command-line Argument.</code></pre> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Android Static Code Check-lint</p></p></span>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.