参照文章:
http://blog.csdn.net/thl789/article/details/8037473
一、简介
Android Lint是SDK Tools 16 (ADT 16)之后才引入的工具,通过它对Android工程源代码进行扫描和检查,可发现潜在的问题,以便程序员及早修正这个问题。Android Lint提供了命令行方式执行,还可与IDE(如Eclipse)集成,并提供了html形式的输出报告。
由于Android Lint在最初设计时就考虑到了independent于IDE,所以它可以很方便的与项目中的其他自动系统(配置/ Build / 测试等)集成.
Android Lint主要用于检查以下这些错误:
1、Missing translations (and unused translations)没有翻译的文本
2、Layout performance problems (all the issues the old layoutopt tool used to find, and more)
3、Unused resources未使用的冗余资源
4、Inconsistent array sizes (when arrays are defined in multiple configurations)在多个配置中的数组大小不一致文件
5、Accessibility and internationalization problems (hardcoded strings, missing contentDescription, etc)
6、Icon problems (like missing densities, duplicate icons, wrong sizes, etc)
7、Usability problems (like not specifying an input type on a text field)
8、Manifest errors
在Eclipse中可以在菜单Window->Preference->“Lint Eerro checking”中设置规则的检查级别,如图1所示。
检查级别可以是:
Default
Fatal
Errro
Waring
Information
Ingore(即不检查)
图1
二、命令行中使用Lint
2.1、基本使用
There is a command line tool in the SDK tools/ directory called lint
.
If you have the SDK
tools/
directory on your path, you can invoke it as “
lint
”. Just point to a specific Android project directory. You can also point to a random directory, which (if it is not an Android project) will be searched recursively and all projects under that directory will be checked. (And you can also specify multiple projects separated by spaces)
在Android SDK的tools下有个叫lint.bat的文件,它就是lint的命令行工具。
lint命令后可以带一个或多个参数,参数之间用空格隔开,参数表示的是需要使用lint进行扫描的Android项目的目录。
示例1
linux命令行
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 warnings
示例2
Window命令行
C:\Documents and Settings\Administrator>lint D:\workspace\Test Scanning Test: ......................................................................................................... ........................................................................................................................ ................... Scanning Test (Phase 2): ...... res\layout\internet_image_demo.xml:9: Warning: The id "button1" is not referring to any views in this layout [UnknownIdI nLayout] android:layout_alignLeft="@+id/button1" ^ res\layout\internet_image_demo.xml:10: Warning: The id "textView1" is not referring to any views in this layout [Unknown IdInLayout] android:layout_below="@+id/textView1" ^ AndroidManifest.xml:52: Warning: Exported receiver does not require permission [ExportedReceiver] <receiver android:name=".AlarmReceiver" > ^ res\menu\activity_main.xml: Warning: The resource R.menu.activity_main appears to be unused [UnusedResources] res\drawable-hdpi\ic_action_search.png: Warning: The resource R.drawable.ic_action_search appears to be unused [UnusedRe sources] res\values\strings.xml:7: Warning: The resource R.string.hello appears to be unused [UnusedResources] <string name="hello">你好!</string> ^ res\drawable-mdpi: Warning: Missing the following drawables in drawable-mdpi: icon.png, icon2.png [IconDensities] res\drawable-xhdpi: Warning: Missing the following drawables in drawable-xhdpi: icon.png, icon2.png [IconDensities] res\layout\internet_image_demo.xml:5: