Run lint when building android studio projects

前端 未结 7 602
予麋鹿
予麋鹿 2020-11-28 07:12

I would like to be able to run the lint task when I\'m building projects with the android studio to ensure the lint rules are being followed.

I have tried using task

相关标签:
7条回答
  • 2020-11-28 08:13

    To do this in build.gradle, add the following lines to your build.gradle:

    android {
      applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def lintTask = tasks["lint${variant.name.capitalize()}"]
            output.assemble.dependsOn lintTask
        }
      }
      ...
    }
    

    This makes all of your assemble tasks depend on the lint task effectively running them before every assemble call that is executed by Android Studio.

    Edit

    With Android Gradle Plugin 3.3 and Gradle 5.x this is a revised version using Kotlin script:

    applicationVariants.all {
      val lintTask = tasks["lint${name.capitalize()}"]
      assembleProvider.get().dependsOn.add(lintTask)
    }
    
    0 讨论(0)
提交回复
热议问题