本文译自androd官方技术文档《Android Lint》,原文地址:http://tools.android.com/tips/lint。
本文地址:http://blog.csdn.net/maosidiaoxian/article/details/41592783。转载请注明出处。翻译如有错讹,敬请指正。
layoutopt
工具会用于查找所有这样的问题,和除此以外更多的问题)lint
。tools/
目录,您可使用“lint
”来调用它。只需指向1个特定的 Android 项目目录。你也能够指向1个随机的目录,(如果它不是1个 Android 的项目)将以递归方式搜索,并将检查该目录下的所有项目。(你还可以指定通过空格分隔的多个项目)。$ 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
$ lint --disable MissingTranslation,UnusedIds,Usability:Icons /src/astrid/
--enable
标志启用它们。--check
标志指定运行哪些确切的检查。这让你可以在代码库中查找1个具体的问题,比如: $ lint --check MissingPrefix /src/astrid/
$ 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
...
--show
命令加上 id 列表或种别 (或不带参数查看全部)可以获得指定的问题的解释:$ 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 文件名
作为参数:$ lint --html /tmp/report.html
$ lint --html /tmp/report.html --url /src/MyProj=http://buildserver/src/MyProj
lint --help
以获得可用参数的相干信息。lint.xml
的文件中,可以通过命令行工具读取。因此,您可以在 UI 中疏忽正告,并在你的源项目关联的lint.xml
文件中进行记录,其他运行着的lint将不会看到你已疏忽的正告(大概是由于已手动验证了)。lint.xml
文件中,所以您的团队中的其他人将会取得你对这个项目编辑的相同的严重性设置。