Official android Technical Documentation translation-Android Lint

Source: Internet
Author: User

Official android Technical Documentation translation-Android Lint

 


Android LintAndroid Lint is a new tool introduced in ADT 16 (and Tools 16) to scan for potential bugs in the Android project source code. It can be used as a command line tool and set ?? In Eclipse (as described below) and IntelliJ (details. This architecture is intended to be independent from the IDE, so it is expected to be integrated with other ides, other build tools, and continuous integration systems.
The following are examples of error types for scanning:
  • Lack of translation (and unused translation)
  • Layout performance problems (oldlayoutoptThe tool is used to find all such problems and more problems)
  • Unused resources
  • Inconsistent array size (when defining arrays in multiple configurations)
  • Accessibility and internationalization problems (hard-coded strings, lack of contentDescription, etc)
  • Icon problems (such as missing density, repeated icons, and incorrect sizes)
  • Availability problem (for example, the input type is not specified on the text field)
  • List errors and other problems.
    See this document for a complete list of problems with the current lint check. For information about how to cancel display (suppress) Specific lint warning information, see the document for canceling warning display.
    If you are interested in writing custom lint checks, you can refer to writing new Lint checks and writing custom Lint rules. Command Line usage in the SDK tool directory, there is a command line tool calledlint. If you have configured the SDKtools/Directory, you can uselintTo call it. You only need to point to a specific Android project directory. You can also point to a random directory (if it is not an Android project) which will be searched recursively and all projects under the directory will be checked. (You can also specify multiple projects separated by spaces ).
    $ 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 warningsThe "ID" of each error type is displayed in brackets after the error message, as shown in the "MissingTranslation" above ".

    You can disable a specific check or a column check by adding -- disable argument, for example:
    $ lint --disable MissingTranslation,UnusedIds,Usability:Icons /src/astrid/
    Note: You can also list categories. For example, the "Usability: Icons" above is the icon sub-category of the Usability category.
    Some checks are disabled by default. You can add--enableFlag to enable them.

    Finally, you can--checkIndicates the exact check to run. This allows you to find a specific problem in the code library, such:
    $ lint --check MissingPrefix /src/astrid/
    If you want to find out which id and category is 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
    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 tag </framelayout>
    ...

    Use--showYou can add the id list or category (or view all without parameters) to the command to get the 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.
    The command line tool for HTML reports can also generate HTML reports. This has some advantages over ordinary lint output:
  • It contains a longer explanation related to each question, and provides a link to More details about this question through a More info attribute.
  • It contains the actual source code lines with errors (a window with three lines of code in the upper and lower layers ).
  • It can contain links associated with the source code file.
  • For the sake of comparison, the error icon is displayed in the Report. to generate an HTML report, you only need to add-- HtmlFile NameAs a parameter:
    $ lint --html /tmp/report.html
    By default, only local file: // path resources are used to link to the source code file. You can use the -- url option to remap URLs to different prefixes. For example:
    $ lint --html /tmp/report.html --url /src/MyProj=http://buildserver/src/MyProjRun other command line optionslint --helpTo obtain information about available parameters.
    Usage in EclipseNote: This document was written at the first release of lint. Eclipse integration has been significantly improved. For more information, seeNew Eclipse Lint UI, Layout Editor Lint Feedback, and Lint Save ).
    Lint is integrated in ADT 16 and later versions. The integration provides several functions of the preceding Lint command line version:
  • Automatic Repair of many warnings
  • Lint can automatically run in various editor operations
  • Some error types and specific error instances on the screen
  • Configure the severity of the problem check
  • Jump from the lint view directly to the problem source code Lint automation will automatically run in the following situations:
  • Export the APK. In this case, the lint runs in special mode. It will only search for fatal errors (this will be faster), and the export will be aborted if any errors are found. You can disable it in the Lint option.
  • Edit and save and XML files, such as layout files or configuration files. In this case, all file range checks that apply to a given file run, and the editor tags are added to any detected problems.
  • Use the layout editor. After each UI operation, a file range check (such as various layoutopt rules) is run on the layout file ), the result is displayed in a special lint window (when an error is found, it can be opened from the error mark displayed in the upper right corner of the layout editor ). To run Lint on a project in the Lint window, select a project in the package browser, and click functions on the Lint toolbar (see the image below ).
    Alternatively, you can right-click the project and choose "Run Lint" from the Android Tools sub-menu. It opens a Lint window that contains various errors. If an error is selected, the associated explanation is displayed in the region on the right.

    If there are any errors in the lint view, you can double-click the error to jump to the associated source code location. The severity of each warning icon is displayed, and a small bulb overlaps with a fixed warning (see the next section.

    This window also has an operation column (in the upper right corner), which allows you
  • Run the lint check again to refresh the result (during the refresh, it will become a Stop button to Stop the check)
  • If an error occurs, run the fix associated with the error.
  • Ignore this fix
  • Delete Alert tag
  • Delete all warning tags
    Quick fixes many lint warnings have automatic fixes. For example, various layoutopt repair replacement tips (for example, replacing wrap_content with 0dp ).
  • From the lint view, click the light bulb to call a repair program.
  • From the layout editor warning summary, click repair to repair.
  • In the XML Code Editor, call the quick fix (Ctrl + 1 or Command + 1) and select the quick fix associated with the alert. Cancel error warning display from the editor quick fix menu, you can also select
  • Ignore this warning in this file only
  • Ignore this warning in this project
  • Ignore this warning during this period.
  • Ignore this advertisement by adding annotations or attributes, which is explained here.

    (If you cannot find the lint fix in the quickfix list, see the known Bug section)

    These options are stored in the project namedlint.xmlCan be read through the command line tool. Therefore, you can ignore the warning in the UI and associatelint.xmlFile, other running Lints will not see warnings you have ignored (probably because they have been manually verified ).
    Option to edit the lint Global Options used for the alternative Options of all projects, you can call the normal Eclipse option dialog box, and select Android> Lint Options:

    If you select an issue, you can edit its severity in the drop-down list in the lower right corner. This allows you to specify some problems as Error (that is, the export APK will be aborted when the options in the dialog box near the top are enabled ).

    To completely disable the problem check, select "Ignore" as the severity.
    Note that this operation does not edit the lint settings for each project.
    . Open the project Setting Dialog Box (right-click the project), where you will find the property page of Android Lint. In the option dialog box, manual severity editing is also recorded together with the error that is not displayed.lint.xmlFile, so others in your team will get the same severity settings you have edited for this project. Subpage (2): ressing Lint Warnings)

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.