Android code review tool-Use of lint Tool

Source: Internet
Author: User

Android code review tool-Use of lint Tool


Reprinted please famous Source: http://blog.csdn.net/lijunhuayc



After so long, I don't know what the lint tool is doing for android. Although I can see it under the android tools Project right-click eclipse every time, what can I do ~ I am ashamed to be an android player ~~~~~

Well, since I have never used it, I have seen it in the past few days and I know what she can do, so I will come to the scene to play with her ~

Do you want to tease her? Come on with me. It's definitely a newbie-level live performance ~

Let's take a look at how Google says:

The AndroidlintTool 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.

In Android Studio, the configuredlintAnd other IDE inspections run automatically whenever you compile your program. You can also manually run inspections in Android Studio by selectingAnalyze> Inspect CodeFrom the application or right-click menu.Specify Inspections ScopeDialog appears so you can specify the desired inspection profile and scope.

In general, the lint tool can checks potential bugs of your project from various aspects. It runs automatically during compilation and running. You can also manually analyze the program. (I am an English dregs ~~~ Cannot be installed later ~~)

Specific details can see here: http://developer.android.com/tools/help/lint.html

There are two ways to Run lint in eclipse. There is a tool with hooks in the toolbar in the upper left corner of the project to check projects in a single or batch, followed by right-clicking the Run lint ....


Okay. Run a project:




I tried it. I don't know whether to check it. So many issues. Don't talk about it, just cry for a while ~~~


Okay. Next, let's take a look at whether there are all problems. Double-click to jump to the corresponding location.


1. The first red error is that multiple identical IDs are defined using @ + id in the layout. The error is because the corresponding layout interface only displays the interface and no data is used for the time being, the layout file is similar and is caused by the copy and paste operation. You can modify the id here.


<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + MqGitdq2/strong + strong/fOqmhlaWdodMr00NS/yctc0v1_8m6iw + strong + szmoaM8L3A + weight + fill = "brush: java; ">

Modify the attributes of the webview parent tag to match_parent. However, we found that the parent tag of webview is a child element of ScrollView. Google recommends that the child element of ScrollView use the warp_parent attribute, so there will be a yellow warning. It doesn't matter.




Check the yellow warning information below in sequence to see which ones need to be modified ~


1. Com. gl. listener. BaseListenerService is not registered in the manifest prompt that this service is not registered in manifest. Check that this service is a base class service and does not need to be registered. Other services are also prompted that they are not registered. Other services are obsolete classes that are not used, and can be deleted directly, resulting in reduced project size.


2. Expected duration Toast. LENGTH_SHORT or Toast. LENGTH_LONG, a custom duration value is not supported prompts Toast. toase is recommended for the duration parameter of makeText. LENGTH_SHORT or Toast. one of LENGTH_LONG, which has no effect and does not need to be modified.

I checked most of the warning information, most of which are irrelevant prompts. They are some of the detailed rules recommended by google, but sometimes these rules are not conducive to our coding. so does not have to be fully observed, for example, when the ImageView control is used, a contentDescription attribute is prompted, but this attribute can be left empty.


3. The resource R. dimen. bottom_tab_padding_drawable appears to be unused prompts that The resource is not used, meaning that The information in these redundant resource files can be deleted. There is also a lot of such information. Troubleshoot. After a large number of screening, project files can be streamlined.



Check that there are more than 300 unused resources, including dairy, animated xml, background xml, string resources, and dimens resources. Deletion can reduce the installation package size. And make the project results clearer. Otherwise, [Today, N years later], when you maintain this project again, it will cause you a headache, because you don't know the purpose of leaving these unused resources at the beginning (of course, this article also applies to code redundancy review, leaving unused code is more difficult to maintain than the resource ).


4. There is also a performance-type warning message. This type of warning information is the warning information that affects the performance. It can be processed as much as possible, for example: this LinearLayout layout or its RelativeLayout parent is possibly useless. In this project, we locate the layout file and find that a RelativeLayout is used on the top layer of the layout, and a LinearLayout is included as the sub-layout. All other layout controls are inside the LinearLayout, that is to say, the layout level here is redundant. The relative layout of the top layer and the linear layout of the second layer are useless. This means that an additional layer of useless layout can be removed. The processing here is to delete the outer RL layout. The advantage of doing so is that the internal layout of LL is dependent on LL layout. If you delete the internal layout of LL, you must adjust it to dependent RL, but deleting RL does not affect the control layout in LL. One word: Convenient !!!




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.