在构建 android studio 项目时运行 lint [英] Run lint when building android studio projects

查看:45
本文介绍了在构建 android studio 项目时运行 lint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在使用 android studio 构建项目时能够运行 lint 任务,以确保遵循 lint 规则.

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.

我曾尝试使用任务依赖项,但没有成功.我的 TeamCity 构建服务器使用运行 lint 任务的构建任务,因此效果很好.但是,当我选择了调试构建变体时,android studio 似乎交替使用 generateDebugSourcescompileDebugJava 任务.

I have tried using task dependencies but with no luck. My TeamCity build server uses the build task which runs the lint task so that works great. However, the android studio appears to use generateDebugSources and compileDebugJava tasks interchangeably when I have selected the debug build variant.

这是我在 build.gradle 中尝试过的:

Here is what I have tried in my build.gradle:

assemble.dependsOn lint

推荐答案

如果你只是想将你的 Android Studio 项目配置为在默认运行配置之前运行 lint 检查而不影响你的 gradle 任务的配置方式,你可以按照这些步骤.

If you just want to configure your Android Studio project to run the lint check before the default run configuration without affecting how your gradle tasks are configured, you can follow these steps.

  1. 打开运行配置下拉菜单并选择编辑

  1. 选择您的应用运行配置

  1. 按+"添加新步骤

  1. 选择Gradle-aware Make"

  1. 输入check"并选择包含您的应用模块名称的选项并进行检查.(我的是 :app:check)

  1. 按向上箭头将新的 check 步骤移动到现有 Gradle-aware make 步骤之前
  1. Press the up arrow to move the new check step before the existing Gradle-aware make step

现在,Android Studio 将运行 lint 检查并在发生任何 lint 错误时使构建失败.

Now, Android Studio will run the lint check and fail the build if any lint errors occur.

这篇关于在构建 android studio 项目时运行 lint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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