我们如何配置 Android Studio 以在每次构建时运行它的 Lint? [英] How Do We Configure Android Studio to Run Its Lint on Every Build?

查看:57
本文介绍了我们如何配置 Android Studio 以在每次构建时运行它的 Lint?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

曾几何时,尤其是在 Eclipse-land 中,Lint 会在每次构建时运行,因此如果您未通过 Lint 检查,您会立即发现.对于 Android Studio(在 1.3 上测试),Lint 默认不会在构建中运行.新人可能会犯一些 Lint 会检查的错误,但由于 Lint 实际上并没有运行,因此新人不会发现这些错误.

(IOW,如果 Lint 测试没有在森林中运行,那么真的有 Lint 测试吗?)

  • 右键单击任务
  • 选择您的执行操作

这应该在计划执行时运行任务.

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 on 1.3), Lint does not run by default on a build. Newcomers might make mistakes that Lint would check, but since Lint doesn't actually run, the newcomers don't find out about them.

(IOW, if a Lint test did not run in a forest, is there really a Lint test?)

Comments on this blog post show how to kinda sorta get Lint to run as part of a build:

  • Edit the project configuration
  • In the General tab of the configuration, scroll down and fold open the "Before launch" panel
  • In that panel, add a step to "Run Gradle Task" named lint for your module

However, this runs command-line Lint, resulting in reports written in XML and HTML to your hard drive. That works, but it would be cleaner to have Android Studio run its in-IDE Lint checks, so the results show up in an IDE panel.

Is there a way to set up a project build to perform the in-IDE Lint checks?

Bonus points if it could be set up to only run Lint, not the full analysis done by Analyze > Inspect Code. While the full analysis is occasionally useful, Lint is slow enough as it is, let alone the dubiously-useful other analysis performed by Android Studio (e.g., spellchecking).

While setting this up would not be a great plan for all projects (Lint scans are slow), for newcomers to Android, it might be an appropriate move.

解决方案

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.

这篇关于我们如何配置 Android Studio 以在每次构建时运行它的 Lint?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆