我们如何配置Android Studio在每个版本上运行它的Lint? [英] How Do We Configure Android Studio to Run Its Lint on Every Build?

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

问题描述

从前,尤其是在Eclipse地区,Lint会在每个版本上运行,因此,如果Lint检查失败,您会立即发现。对于Android Studio(在1.3版上进行了测试),Lint默认情况下不会在构建版本上运行。新人可能会犯错Lint会检查的错误,但是由于Lint并未真正运行,因此新人不会了解它们。



(爱荷华州,如果进行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天全站免登陆