Run lint when building android studio projects

前端 未结 7 727
予麋鹿
予麋鹿 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 07:48

    If you want to force Android Studio project to run the lint check before the default run configuration without affecting how your gradle tasks are configured, AND you want to do this in the gradle build system, then you can add the following block outside of the android block in the app module's build.gradle as follows:

    android {
    ....
        lintOptions {
            abortOnError true
        }
    }
    
    tasks.whenTaskAdded { task ->
        if (task.name == 'compileDevDebugSources') {
            task.dependsOn lint
            task.mustRunAfter lint
        }
    }
    

    Replace compileDevDebugSources with the desired build variant that you have already defined, eg. compileReleaseSources, compileDebugSources, compileStagingDebugSources, etc.

    This was tested working on Android Studio 3.0

提交回复
热议问题