Android Official Technical Document translator--android Lint

Source: Internet
Author: User
Tags locale

This article is translated from Androd official technical document "Android Lint", the original address: Http://tools.android.com/tips/lint.

This article address: http://blog.csdn.net/maosidiaoxian/article/details/41592783. Reprint please indicate the source. Please correct me if there is any inappropriateness in the translation.



Android LintAndroid Lint is a new tool introduced in ADT 16 (and tools 16) to scan for potential bugs in the source code of Android projects. It can be used as a command-line tool as well as a set?? Into eclipse (as described below), and IntelliJ (more information). This architecture is intentionally independent of the IDE, so it has the potential to integrate with other Ides, other build tools, and continuous integration systems.
Here are some examples of the types of errors that it scans:
    • Lack of translations (and unused translations)
    • Layout performance issues (old layoutopt tools will be used to find all of these issues, and more questions beyond)
    • Resources not in use
    • Inconsistent array size (when arrays are defined in multiple configurations)
    • Accessibility and internationalization issues (hard-coded strings, missing contentdescription, etc.)
    • Icon problems (such as missing density, repeating icon, error size, etc.)
    • Usability issues (such as the type of input not specified on the text field)
    • Manifest error
And a lot more questions.
See this document for a complete list of issues that are currently checked by lint. For information about how to suppress a display (suppress)-specific lint warning, see suppress a warning from a document that appears.
If you are interested in writing a custom Lint check, you can refer to writing a new Lint check and writing a custom Lint rule. Command line usage in the SDK Tools directory there is a command-line tool called lint。 If the SDK is already configured on your path, the tools/directory, you can use the lint"To invoke it. Just point to a specific Android project directory. You can also point to a random directory, (if it's not an Android project) will search recursively and will check all items in that directory. (You can also specify multiple items separated by a space).
$ lint /src/astrid/
Scanning GreenDroid-GoogleAPIs: ..
Scanning stream: ...
Scanning api: ...........................
Scanning GDCatalog: .......................
Scanning GreenDroid: ...........................................................
Scanning tests: ...
Scanning filters: ....
Scanning tests: .....
Scanning astrid: ....................................................................................................................................................
Scanning simple: .......
api/res/values-ca: Error: Locale ca is missing translations for: sync_SPr_bgwifi_key, sync_SPr_forget_key, sync_SPr_interval_values, sync_SPr_logged_in_prefix... (2 more) [MissingTranslation]
astrid/res/values-ca: Error: Locale ca is missing translations for: DLG_cancel, DLG_dismiss, DLG_ok, EPr_deactivated... (117 more) [MissingTranslation]
api/res/values-cs: Error: Locale cs is missing translations for: sync_SPr_bgwifi_key, sync_SPr_forget_key, sync_SPr_interval_values, sync_SPr_logged_in_prefix... (2 more) [MissingTranslation]
(many lines omitted)
43 errors, 466 warningsDisabling the check "ID" for each type of error appears in parentheses after the error message, such as "missingtranslation" above.

You can disable a specific check, or a column of checks, by adding--disable argument, for example:
$ lint --disable MissingTranslation,UnusedIds,Usability:Icons /src/astrid/
Note that you can also list categories such as "Usability:icons" above, which is the subcategory of icons for sex categories.
Some checks disable the status by default. Can be added by adding --enableFlag to enable them.

Finally, you can --checkflag specifies which exact checks to run. This allows you to find a specific problem in the code base, such as:
$ lint --check MissingPrefix /src/astrid/
If you want to find out which ID and category are available, run
$ lint --list
Valid issue categories:
Correctness
Security
Performance
Usability
Usability:Icons
Accessibility
Internationalization

Valid issue id‘s:
"ContentDescription": Ensures that image widgets provide a contentDescription
"DuplicateIds": Checks for duplicate ids within a single layout
"StateListReachable": Looks for unreachable states in a <selector>
"InefficientWeight": Looks for inefficient weight declarations in LinearLayouts
"ScrollViewSize": Checks that ScrollViews use wrap_content in scrolling dimension
"MergeRootFrame": Checks whether a root <FrameLayout> can be replaced with a <merge> tag
...

Use --showThe command adds an ID list or category (or no parameters to view all) to get an explanation of the specified problem:

$ lint --show MissingPrefix
MissingPrefix
-------------
Summary: Detect XML attributes not using the Android namespace

Priority: 8 / 10
Severity: Warning
Category: Correctness

Most Android views have attributes in the Android namespace. When
referencing these attributes you *must* include the namespace prefix,
or your attribute will be interpreted by aapt as just a custom
attribute.
HTML reports This command-line tool can also generate HTML reports. This has some advantages over the normal lint output:
    • It contains a longer explanation of each problem and provides links to more detailed information about the problem through a more info property.
    • It contains the actual source code line with the error (a window with three lines of code on top and bottom).
    • It can contain a link to the source code file
    • For the error icon, the icon itself will be displayed in the report for comparison purposes
To generate an HTML report, you only need to add --html 文件名As a parameter:
$ lint --html /tmp/report.html
By default, linking to a source code file uses only the local file://path resource. You can remap the URL to a different prefix by using the--url option. For example:
$ lint --html /tmp/report.html --url /src/MyProj=http://buildserver/src/MyProjOther command-line options run lint --helpTo get information about the available parameters.
Usage in Eclipse Note : This document was written when Lint was first published. Eclipse integration has been significantly improved. For more up-to-date details, seeThe new Eclipse Lint UI, the Lint UI, layout editor Lint feedback (layouts Editor Lint Feedback) and Lint Save (Lint on Save).
The Lint is integrated on ADT 16 and later. The integration provides several features of the Lint command line version described above:
    • Automatically fix many warnings
    • Lint can be run automatically in various editor actions
    • Screen some error types and specific error instances
    • Configuring the severity of the problem check
    • Jump directly to the problem source from the lint view
Lint Automation Lint will run automatically when the following conditions occur:
    • Export APK. In this case, the lint is run in a special mode, which will only look for fatal errors (this will be faster) and will abort the export if any errors are found. You can turn it off in the Lint option.
    • Edit and save and XML files, such as layout files or manifest files. In this case, all file scope checks that apply to a given file run, and the editor's markup is added to any discovered issues.
    • Use the Layout editor. After each UI action, file scope checks (such as various layoutopt rules) are run on the layout file, and the results are displayed in a special lint window (it can be opened from the error tag that appears in the upper-right corner of the layout editor when an error is found).
Lint window to run Lint on a project, select the item in the package browser and click Functions on the Lint toolbar (see picture below).
Or you can right-click on the project and have a "run Lint" feature in the Android Tools submenu. It will open a Lint window that contains various errors. Selecting an error will display an associated explanation in the text area on the right.

If there are any errors on the lint view, you can double-click on the error to jump to the associated source code location. Each warning icon will show its severity and will have a small bulb overlap for the repaired warning (see next section).

The window also has an action bar (in the top right corner) that allows you to
    • Run the lint check again to refresh the results (it becomes a stop button during refresh, which is used to abort the check)
    • If there is an error, run the fix associated with this error
    • Ignore this fix
    • Remove warning flags
    • Remove all warning flags

Quick fix many lint warnings have automatic repair function. For example, replacement hints for various layoutopt fixes (such as replacing wrap_content with 0DP).
    • From the lint view, click the light bulb to invoke a hotfix.
    • From the Layout Editor warning summary, click the Fix it button to fix it.
    • From the XML code Editor, call quick fix (ctrl+1 or command+1) and select the quick fix associated with the warning.
Canceling the display of error warnings from the editor quick fix menu, you can also select
    • Only this warning in this file is ignored
    • Ignore this warning in this project
    • This warning is ignored during this time.
    • Ignore this ad by adding annotations or attributes, which are explained here.


(If you can't find a fix for lint in the Quickfix list, see the Known bugs section)

These choices are stored in the project named lint.xmlFile, you can read it from the command line tool. As a result, you can ignore the warning in the UI and associate it in your source project. lint.xmlFiles, other running lint will not see the warnings you have ignored (presumably because they have been manually verified).
Option to edit the lint global option for all project alternatives, you can invoke the normal Eclipse Options dialog box and choose Android > Lint options:

If you select a problem, you can edit its severity in the drop-down list in the lower-right corner. This allows you to designate some issues as Error (that is, to abort the export of the APK if the option is enabled near the top of the dialog box).

To turn off the problem check completely, select Ignore as the severity.
Note that this action does not edit the lint settings for each item
。 Open the Project Settings dialog (right-click the project), where you will find the Properties page for the Android Lint. Manual severity Editing in the Options dialog box is also recorded along with the error that is displayed in the lint.xmlFile, so other people on your team will get the same severity settings that you edit for this project. Child page(2):suppress the display of Lint warnings (suppressing Lint Warnings)Write a Lint check (Writing a Lint check)

Android Official Technical Document translator--android Lint

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.