Android - set all lint warnings as errors except for certain ones

佐手、 提交于 2019-12-05 02:24:05

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>

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.

It doesnt seem informational is a real option from this doc, I suggest:

android {
    lintOptions {
        checkAllWarnings true
        warningsAsErrors true
        // use this line to check all rules except those listed
        disable 'MissingTranslation', ...
        //OR this line to check but not worry about result (i think this is what you want)
        ignore 'MissingTranslation', ...
    }     
}

For me, this configuration worked:

android {
    lintOptions {
        warningsAsErrors true
        warning 'MissingTranslation', ...
    }
}

It seems the options are evaluated in the "correct order" (aka "as I need it"), i.e. first all warnings are elevated to errors, then this settings is overriden again for a single issue id. Using warning instead of disable or ignore ensures the issues are still visible in the report or the IDE.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!