Search code examples
androidandroid-lint

Android Lint Config file - How to enable rules?


I have lint.xml file

<lint>
    <issue id="AdapterViewChildren" severity="warning" />
    <issue id="OnClick" severity="error" />
    <issue id="StopShip" severity="fatal" />
</lint>

by default StopShip lint rule is disabled. --> StopShip is just an example I have all the rules in lint.xml file as listed http://tools.android.com/tips/lint-checks

Below is my lint options

lintOptions {
    //http://tools.android.com/tips/lint-checks
    // If set to true, turns off analysis progress reporting by lint.
    isQuiet = true
    // if set  to true (default), stops the build if errors are found.
    isAbortOnError = false
    // Returns whether lint will only check for errors (ignoring warnings)
    isIgnoreWarnings = false
    /*
     * Whether lint should include all output (e.g. include all alternate locations, not truncating
     * long messages, etc.)
     */
    isShowAll = true
    /*
     * Whether lint should ignore all test sources. This is like [isCheckTestSources], but always
     * skips analyzing tests -- meaning that it also ignores checks that have explicitly asked to
     * look at test sources, such as the unused resource check.
     */
    isIgnoreTestSources = true
    /*
     * Whether lint should check for fatal errors during release builds. Default is true. If issues
     * with severity "fatal" are found, the release build is aborted.
     */
    isCheckReleaseBuilds = false

    var workingDir = File("$projectDir").parentFile
    lintConfig = File("$workingDir/lint.xml")

When I run the lint rules report is generated however, it shows few lint checks are disabled. Do I need to explicitly add enable("xyz","abc",...) (where xyz, abc ... are default disabled) tag in lintOptions ? I have already listed default disabled lint checks in lint.xml config file

Any help is much appreciated.


Solution

  • Yes, you must enable them in app/build.gradle or some appropriate high-level Gradle config:

    lint {
       enable += "StopShip"
    }
    

    lint.xml doesn't seem to be able to enable/disable specific rules, which is sad as it forces lint configuration to be spread out across the codebase.

    Also, note specifically about StopShip:

    In Gradle projects, this is only checked for non-debug (release) builds.