Android-Lint: powerful tool for error detection and code optimization

Source: Internet
Author: User

Tian haili

2012-10-03

 

Android-Lint is a tool introduced after SDK tools 16 (ADT 16). It can detect potential problems through code check and optimize the android program. Android-Lint provides command line execution, integration with IDE (such as Eclipse), and HTML output reports. Android-Lint can be easily integrated with other automatic systems in the project (configuration/build/test, etc.

 

Android-lint-related articles:

  • Android-Lint: powerful tool for error detection and code optimization

A brief description of Android-Lint: lint checks the problems, how to use them, what options are available, and integrates with other systems.

  • Customize existing Android-Lint check rules

Handle problems found in Android-lint. Customizable rules used in projects.

  • Android-Lint check problem list

All default checks supported by Android SDK tools/ADT plugin 0.3.

The English version and the Chinese version are available. The English version is exported directly from Android-lint. The Chinese version is incomplete, and the explanation of each article will be improved gradually.

 

Of course, the most important and most authoritative should look at the official website: http://tools.android.com/tips/lint

 

 

I. potential problems with Android-Lint check

 

1.1 Problem description-issue

 

Android-LintIssue.

Issue is divided into nine categories (Category): Correctness/correctness: messages/security/performance/usability: typography/usability: icons/usability/accessibility/internationalization.

Issue uses a text phraseID, Issue customization and other operations are based on ID.

Issue usesSeverityTo identify the severity of the vulnerability: Fatal/error/warning/information/ignore. The ignore operation on issue actually reduces its severity to ignore.

 

1.2 potential problems

 

For potential problems detected by Android-lint, you can use the command line $ lint -- show to obtain a detailed list of problems to be scanned.

 

The following describes the common problems checked by Android-Lint:

1. correctness1) the ID in duplicatedidslayout should be unique. 2) Some APIs used in newapi code are higher than min sdk3 in manifest.) inconsistentarrays string is internationalized, the item values of the string-array with the same name are different. 4) registeredactivity/service/contentprovider is not registered through androidmanifest. 5) Deprecated uses obsolete api6) pxusage to avoid using PX, use DP 2. correctness: messeges1) missingtranslation string internationalization is not complete 2) extratranslation internationalization string, in the default position (defaultlocale), not defined 3. security1) setjavascriptenabled is not sure whether your program is If Javascript is required, do not execute setjavascriptenabled. 2) When the exportedcontentprovider/exportedreceiver/exportedservice/exportedactivitycontentprovider/Explorer/service/activity exported is true, set a permission so that the user can use the permission. 3) do not set Android: debuggable in manifest in hardcodeddebugmode. Set it. Any compiled version must adopt the specified debug mode. If this parameter is not set, compile the Eng version in debug mode. Compile the user version in release mode. 4. performance1) drawallocation avoids assigning objects when drawing or parsing a layout (draw/layout. E. g., instantiate the paint object in ondraw. 2) useless parameters in obsoletelayoutparamlayout. 3) usecompounddrawables: for example, a linear layout containing an imageview and a textview can be replaced by a textview of compounddrawable. 4) usesparsearrays use Android sparsearray instead of hashmap5) disablebaselinealignment if linearlayout is used for nested layout space computing, its Android: baselinealigned attribute should be set to false to accelerate layout computing. 6) floatmath uses floatmath instead of math. 7) nestedweights avoid nesting weight, which will drag down the execution efficiency 8) unusedresources/unusedids unused resources will increase the program and reduce the compilation speed. 9) If overdraw specifies a background drawable for rootview, it will first draw the background of theme and then use the specified background. This is the so-called "overdraw ". You can set theme's background to null to avoid this. 10) the father of uselessleaf, uselessparentview, or view is useless. usability: typography1) special characters of typographydashes must be replaced by encoding: "-" must be replaced by "-"; "-" must be replaced by "-" 2) special characters of typographyellipsis must be replaced by encoding: "…" You need to use "…" 3) typographyother problem: "(c)" needs to use "" 6. Usability: icons1) iconnodpiicon to appear in both nodpi and specified DPI directories. 2) gifusageimage do not use GIF. It is best to use PNG or JPG. 7. usability1) do not design Back buttons in backbuttonandroid. Generally, Back buttons are used in Android. 2) The "OK"/"cancel" of buttoncasebutton must be case-insensitive. Strings with standard resources should not be defined by yourself, but should be defined by the system: @ Android: String/OK and @ Android: String/cancel 8. accessibility1) contentdescriptionimageview and imagebutton should provide contentdescription 9. internationalization1) The hardcodetext hardcoded string should be defined in the resource 2) enforceutf8 all XML resource files should be encoded in UTF-8...

 

2. run Android-Lint

 

1.1 run in eclipse

 

The runs Android lint button in eclipse.

Click it to execute Android lint for all the android projects in the current workspace. You can also click the down arrow on the right of it and select to execute Android lint for an android project.

After the lint check is executed, the result of the check is in the lint warnings view of Eclipse:

 

You can solve the problem here or customize to ignore the problem.

 

1.2 command line execution

 

The lint command line is in androidsdk tools, and the lint. bat batch file is available under <Android-SDK-root> \ tools.

Execute> lint <DEST> to perform all android projects in <DEST>RecursionCheck.

 

3. Android-Lint options

 

In the command line, Android-Lint provides the write parameter option and customization.

3.1 issue list

lint --showlint --list

Show and list can be used to view the list of all issue that can be detected. Show shows detailed issue information. list is only the list of issue IDs and summary.

 

3.2 disable/enable/check issue

lint --disable <list>lint --enable <list>lint --check <list>

Android-Lint supports the list of issue to be checked. The default value is check (severity is not ignore) and ignore (severity is ignore.

You can use disable to check the ID or category to be checked by default in the specified <list>; use enable to check the ID or category ignored by default in the specified <list>; use check to check only the ID or category in the specified <list>.

Note:

[1] disable/enable is based on the default list. Disable/enable is given in the list. Check only checks in the list.

[2] <list> is an issue ID or category list separated by commas.

 

3.3 HTML output

lint --html <filename>lint --html <filename> --url filepath=url

Android-Lint can specify the result output of this check using the HTML option.

In the generated HTML file, other files are also referenced. You can replace the address with the URL parameter to point it to the public access location.

 

3.4 specify the global configuration file

lint --config <filename>

Although the disable/enable/check option can change the problematic behavior of this check, it will be specified again next time. You can use the config option to specify the default global configuration file.

Note: If the project already has lint. XML file. For an issue check, 1 first uses lint in the project. XML rules, followed by the rules specified by 2config, and finally the default rules of 3.

 

3.5 Other Options

lint --help

Android-Lint has many other options, which can be viewed through lint -- help.

 

4. integration with other systems

 

Android-Lint provides command line and IDE integration. The IDE can greatly improve individual combat capabilities, while the command line is vital to the team. If a tool is to be used in an automatic system, whether the command line execution mode is supported is an important indicator.

Android-Lint is fully available and can be integrated with the existing configuration system, automatic build system, and automatic test system:

  •  Configuration SystemThere are resourcesAdd or change(The trigger time can also be daily build/weekly build/etc .)
  • TriggerAutomatic Build SystemDoBuild;
  • After the build is complete, startAndroid-Lint SystemExecute lint for check;

Result of lint checkDetermine the version quality in the form of an HTML report together with the automatic test resultsImportant indicators.

 

 

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.