且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android - 将所有 lint 警告设置为错误,但某些警告除外

更新时间:2022-06-14 17:18:00

如果不使用 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.