本文译自androd官方技术文档《Android Lint》,原文地址:http://tools.android.com/tips/lint。
本文地址:http://blog.csdn.net/maosidiaoxian/article/details/41592783。转载请注明出处。翻译如有错讹,敬请指正。
Android
Lint是在ADT 16(和 Tools 16)引入的1个新工具,可以扫描Android 项目源码中潜伏的bug 。它可同时作为1个命令行工具,和集??成在Eclipse(以下所述),和IntelliJ(详细信息)中。这个架构是成心独立于IDE的,因此它有希望与其他的IDE,其他的构建工具和延续集成系统集成。
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 --listValid issue categories:CorrectnessSecurityPerformanceUsabilityUsability:IconsAccessibilityInternationalizationValid 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 MissingPrefixMissingPrefix-------------Summary: Detect XML attributes not using the Android namespacePriority: 8 / 10Severity: WarningCategory: CorrectnessMost Android views have attributes in the Android namespace. Whenreferencing these attributes you *must* include the namespace prefix,or your attribute will be interpreted by aapt as just a customattribute.--html 文件名 作为参数:$ lint --html /tmp/report.html$ lint --html /tmp/report.html --url /src/MyProj=http://buildserver/src/MyProjlint --help以获得可用参数的相干信息。





lint.xml的文件中,可以通过命令行工具读取。因此,您可以在 UI 中疏忽正告,并在你的源项目关联的lint.xml文件中进行记录,其他运行着的lint将不会看到你已疏忽的正告(大概是由于已手动验证了)。

lint.xml文件中,所以您的团队中的其他人将会取得你对这个项目编辑的相同的严重性设置。