Android - 将所有 lint 警告设置为错误,但某些警告除外 [英] Android - set all lint warnings as errors except for certain ones

查看:44
本文介绍了Android - 将所有 lint 警告设置为错误,但某些警告除外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当引入不在 lint-baseline.xml 文件中的新 lint 警告时,我试图使我的持续集成失败.我希望将所有 lint 警告视为错误(因此构建被中止),但我想要一种方法来指定某些 lint 检查被视为信息或警告级别,以便它们仍然出现在 lint 结果中,但不要不会导致构建中止.

I am trying to make my continuous integration fail the build when new lint warnings that aren't in the lint-baseline.xml file are introduced. I want to have all lint warnings treated as errors (so the build is aborted), but I'd like a way to specify certain lint checks to be treated as informational or warning level so that they still appear in the lint results, but don't cause the build to be aborted.

这里是我想要做的基本上的一个例子(除了这不起作用,如果存在任何不可忽略的警告,构建就会失败):

Here is an example of basically what I'd like to do (except this doesn't work, the build fails if any non-ignored warnings exist):

lintOptions {
    lintConfig file("lint.xml")
    baseline file("lint-baseline.xml")
    checkAllWarnings true
    warningsAsErrors true
    abortOnError true
    informational 'MissingTranslation, ...' // don't fail the build for these
}

是否有一种简单的方法可以将所有 lint 检查视为错误,但不包括某些错误?我曾考虑将所有 200 多个 lint 检查手动设置为错误级别,但这不是未来的证明,因为每次添加新的 lint 检查时我都必须更新列表.

Is there an easy way to treat all lint checks as errors, excluding certain ones? I thought about manually setting all 200+ lint checks to the error level, but that wouldn't be very future proof, since I'd have to update the list every time new lint checks were added.

推荐答案

如果不使用 Gradle lintOptions (checkAllWarningswarningsAsErrors 等)来配置哪些警告应该被视为错误.改用 lint.xml.您可以在那里执行以下操作:

You should be able to achieve what you want if you do not use the Gradle lintOptions (checkAllWarnings, warningsAsErrors, etc.) to configure which warnings should be treated as errors. Use lint.xml instead. There you can do the following:

<?xml version="1.0" encoding="UTF-8"?>
<lint>
   <issue id="MissingTranslation" severity="warning" />

   <!-- The following must be at the bottom of your file!
        All lint issues (not listed above) will be treated as errors. -->
   <issue id="all" severity="error" />
</lint>

在我的测试中,这似乎工作正常,除 lint.xml 顶部列出的警告外,所有警告都被视为错误.但是,我还没有将它与 lint-baseline.xml 结合使用进行测试,但我认为没有理由它不应该在那里工作.

In my tests this seemed to work fine and all warnings were treated as errors except for those listed at the top of the lint.xml. However, I've not tested it in combination with a lint-baseline.xml but I see no reason why it shouldn't work there as well.

这篇关于Android - 将所有 lint 警告设置为错误,但某些警告除外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆