Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
}

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.

like image 967
starkej2 Avatar asked Mar 10 '17 00:03

starkej2


People also ask

What is lintOptions?

lintOptions { abortOnError false } This means it will run lint checks but won't abort the build if any lint error found. By default, its true and stops the build if errors are found.

How do you use lint on Android?

To utilize Lint or just run inspections in your project, add Lint inspection to the lint. xml file or manually pick the list of issues to be configured by Lint in your project using Android Studio. Configure the lint file: Add the list of issues to be configured in the lint.


1 Answers

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.

like image 146
Araxias Avatar answered Oct 01 '22 06:10

Araxias