How Do We Configure Android Studio to Run Its Lint on Every Build?

前端 未结 4 532
清酒与你
清酒与你 2020-12-12 19:21

Once upon a time, particularly in Eclipse-land, Lint would run on every build, and so if you failed Lint checks, you would find out immediately. With Android Studio (tested

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 20:23

    Lint should be running in Android Studio unless you have configured it to be off via the lintOptions in your build.gradle file.

    Here is from the documentation found at http://developer.android.com/tools/debugging/improving-w-lint.html#studio

    In Android Studio, the configured lint and IDE inspections run automatically whenever you build your app. The IDE inspections are configured along with the lint checks to run IntelliJ code inspections to streamline code review.

    Note: To view and modify inspection severity levels, use the File > Settings > Project Settings menu to open the Inspection Configuration page with a list of the supported inspections.

    With Android Studio, you can also run lint inspections for a specific build variant, or for all build variants from the build.gradle file. Add the lintOptions property to the android settings in the build file. This code snippet from a Gradle build file shows how to set the quiet option to true and the abortOnError option to false.

    android {
        lintOptions {
           // set to true to turn off analysis progress reporting by lint
           quiet true
           // if true, stop the gradle build if errors are found
           abortOnError false
           // if true, only report errors
           ignoreWarnings true
           }
           ...
    }
    

    To manually run inspections in Android Studio, from the application or right-click menu, choose Analyze > Inspect Code. The Specify Inspections Scope dialog appears so you can specify the desired inspection scope and profile.

    Here are other lint options that you can add to your lintOptions block in your gradle build.gradle file: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Lint-support

    Here is more information on android lint: http://developer.android.com/tools/help/lint.html

    It use to be that you could add gradle tasks after certain actions in android studio.

    • Open up the Gradle tab on the right side of the screen
    • Select your task

    • Right click on the task
    • Choose your execution action

    This should run the task when it has been scheduled for execution.

提交回复
热议问题