忽略Android lint中的多个警告

26

我知道我可以使用属性tools:ignore忽略 Lint 中的一条规则。

我的困难在于我想要忽略多条规则。对于Google Analytics中的ga_trackingId,我想要忽略TypographyDashesMissingTranslation

我已经尝试过但没有成功。

<resources tools:ignore="TypographyDashes|MissingTranslation" xmlns:tools="https://schemas.android.com/tools" >

<resources tools:ignore="TypographyDashes,MissingTranslation" xmlns:tools="https://schemas.android.com/tools" >

<resources tools:ignore="TypographyDashes MissingTranslation" xmlns:tools="https://schemas.android.com/tools" >

我现在想不出来了。我如何在tools:ignore中指定多个值?


4
根据文件,逗号分隔列表应该可以实现这个。请参见此开发者页面底部:http://developer.android.com/tools/debugging/improving-w-lint.html - harism
1
谢谢@harism提供指针。我已经打开了问题43070。 - rds
@harism,命名空间方面你发现得真好;我想把被接受的答案归功于你。 - rds
4个回答

49
你需要使用逗号分隔的列表,但是不能有空格。
例子:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" // required to work
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="contentDescription,SpUsage" > // comma separated list. NO blanks allowed!

你可以从命令行获取有效选项列表,或使用由throrin19提到的Eclipse Lint错误检查列表。

lint --list > lint_options.txt

请参阅lint文档


这正是我要找的。 :) - iroiroys

8
这里的问题是在xml资源文件中使用了错误的命名空间URI。
xmlns:tools="https://schemas.android.com/tools"

原本应该是 http://...协议。更多细节请参考43070问题


总之:不要按照文档使用,而是使用“http”命名空间 :) - rds

2
您可以在特定字符串上放置多个注释以忽略多个Lint检查: < p >您可以在特定的字符串上放置多个注释,以忽略多个代码规范检查:< /p > < p >strings.xml< /p >
<?xml version="1.0" encoding="utf-8"?>
<resources>    

    <!--suppress MissingTranslation -->
    <!--suppress TypographyDashes -->
    <string name="some_string">ignore my translation</string>
    ...

</resources>

http://tools.android.com/tips/lint/suppressing-lint-warnings


该网站已被禁用。 - Abhinav Saxena

2

你使用过Eclipse或IntelliJ吗?

在Eclipse中,转到“Window” -> “Preferences” -> “Android” -> “Lint Error Checking”

enter image description here

玩得愉快;-)


它有帮助,但这个配置的范围不同。 - rds
这张图片被用来说明你即将发生的事情。 - throrin19

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接