37

could someone tell me a way to avoid executing "lint" each time I run in gradle check?

I've defined in build.gradle

lintOptions { 

    quiet true 

}

However, it keeps doing this task. The problem is that it takes ages each time I have to do a check.

Jose M Lechon
  • 5,766
  • 6
  • 44
  • 60

10 Answers10

86
gradle build -x lint 

Source: Gradle User Guide : Excluding Tasks

kukido
  • 10,431
  • 1
  • 45
  • 52
44

You can skip it using adding -x lint when you run the check task:

./gradlew check -x lint 

If you want to skip it permanently you can add this to your build.gradle before apply plugin: 'com.android.application':

tasks.whenTaskAdded { task ->
    if (task.name.equals("lint")) {
        task.enabled = false
    }
}
Display Name
  • 8,022
  • 3
  • 31
  • 66
rciovati
  • 27,603
  • 6
  • 82
  • 101
23

I just disabled the task during project setup:

android {
    lintOptions {
        tasks.lint.enabled = false
    }
}

Note: it's not necessary to put the statement inside android.lintOptions, but since it's configuring lint, it's nice to have them together.

TWiStErRob
  • 44,762
  • 26
  • 170
  • 254
7

Set checkReleaseBuilds to false will disable lint check on release build. Add following scripts to your build.gradle file:

lintOptions {
     /**
     * Set 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.
     */
    checkReleaseBuilds false
}
codezjx
  • 9,012
  • 5
  • 47
  • 57
4

(Gradle 1.1.0, as packaged with Android Studio 1.1.0)

For anyone wondering how to do this with multiple subprojects, I ended up having to disable them using the root project build.gradle file like so:

task lintCheck() {
    getAllTasks(true).each {
        def lintTasks = it.value.findAll { it.name.contains("lint") }
        lintTasks.each {
            it.enabled = false
        }
    }
}
Zenel
  • 311
  • 1
  • 7
1

If you happen to have different build variants, perhaps a more robust script solution would be

afterEvaluate {
  Set<Task> result = tasks.findAll { task -> task.name.startsWith('lintVital') }
  result.each { Task task ->
    task.enabled = false
  }
}
Sebastiano
  • 12,289
  • 6
  • 47
  • 80
1

use this code to disable all lint tasks using Gradle's new configuration avoidance API:

tasks.withType(com.android.build.gradle.tasks.LintBaseTask).configureEach {
    enabled = false
}

(tested on Android Gradle plugin 3.3.2.)

Lanchon
  • 343
  • 3
  • 7
1

-x lint not worked for com.android.tools.build:gradle:3.5.4

you should use -x lintVitalRelease -x lint -x lintVitalSourceSets instead.

For example:

gradlew --stacktrace build -x lintVitalRelease -x lint -x lintVitalSourceSets
BaiJiFeiLong
  • 3,716
  • 1
  • 30
  • 28
0

If you still want the lint task to work you can also:

project.tasks.check.dependsOn.remove("lint")
Yu Han
  • 1
  • 1
0

In my case somehow nice solutions was not working so I looked in the error file lint-results-debug.txt and just disable errors that was actually not real issues in my code but more bugs of limited lint. Like this one:

.../Users/renetik/Development/renetik-instruments-android/project/renetik-instruments-library/src/main/res/layout/controller_chord.xml:9: Error: No orientation specified, and the default is horizontal. This is a common source of bugs when children are added dynamically. [Orientation]...

So I added to module build gradle of renetik-instruments-library

android {
    ...
    lintOptions {
        disable 'IncludeLayoutParam', 'Orientation', 'UseAppTint'
    }
}

Now build works... and useful lint checks still there.

But also for build performance improvement of complex project this can be miracle:

afterEvaluate {
    tasks.findAll { it.name.startsWith('lint') }.each { it.enabled = false }
}

But you have to place or included in each module build.gradle it doesn't work in project build.gradle If its correctly aplied you can see

Task :renetik-instruments-app:lintVitalAnalyzeDebug SKIPPED

in Build Output console.

Renetik
  • 5,887
  • 1
  • 47
  • 66