gradle build fails on lint task(gradle build 在 lint 任务上失败)
问题描述
我有一个使用 Android Studio 0.4.0 创建的简单 android 项目.我使用 Gradle 1.9 和 Gradle Android 插件 0.7.昨天我在我的 gradle 构建脚本中添加了 Jake Wharton 的 ButterKnife 库:
I have a simple android project that I created with Android Studio 0.4.0. I use Gradle 1.9 and Gradle Android Plugin 0.7. Yesterday I've added Jake Wharton's ButterKnife library in my gradle build script:
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:appcompat-v7:19.0.0'
// Butterknife
compile 'com.jakewharton:butterknife:4.0.1'
}
当我从 Android Studio 运行应用程序时,构建运行良好并在我的设备上正确执行.但是当我尝试(从命令行) gradle build 构建失败.这是我的 lint 报告中的一部分:
When I run the application from Android Studio, the build runs fine and executes correctly on my devices. But when I try (from the command line) gradle build the build fails. Here is a part from my lint report:
InvalidPackage: Package not included in Android
/home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar: Invalid package reference in library; not included in Android: javax.annotation.processing. Referenced from butterknife.internal.InjectViewProcessor.
/home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar: Invalid package reference in library; not included in Android: javax.annotation.processing. Referenced from butterknife.internal.InjectViewProcessor.
/home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar: Invalid package reference in library; not included in Android: javax.annotation.processing. Referenced from butterknife.internal.InjectViewProcessor.
/home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar: Invalid package reference in library; not included in Android: javax.annotation.processing. Referenced from butterknife.internal.InjectViewProcessor.
/home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar: Invalid package reference in library; not included in Android: javax.annotation.processing. Referenced from butterknife.internal.InjectViewProcessor.
也许我遗漏了一些东西,但无法在终端中构建项目阻止了 CI 用于 Android 项目的可能性.
Maybe I'm missing something, but not to be able to build the project in the terminal blocks the possibility of CI for Android projects.
任何帮助都会很棒.
推荐答案
0.7.0 提供了对 Lint 的扩展支持,但是,它并不总是能正常工作.(例如,butterknife 库)
With 0.7.0 there comes extended support for Lint, however, it does not work always properly. (Eg. the butterknife library)
解决方案是在发现 lint 错误时禁用中止构建
Solution is to disable aborting build on found lint errors
我的灵感来自https://android.googlesource.com/platform/tools/base/+/e6a5b9c7c1bca4da402de442315b5ff1ada819c7
(实现:https://android.googlesource.com/platform/tools/base/+/e6a5b9c7c1bca4da402de442315b5ff1ada819c7/build-system/gradle/src/main/groovy/com/android/build/gradle/internal/model/DefaultAndroidProject.java)
(讨论:https://plus.google.com/+AndroidDevelopers/posts/ersS6fMLxw1)
android {
// your build config
defaultConfig { ... }
signingConfigs { ... }
compileOptions { ... }
buildTypes { ... }
// This is important, it will run lint checks but won't abort build
lintOptions {
abortOnError false
}
}
<小时>
如果您只需要禁用特定的 Lint 规则并让其他人的构建失败,请使用:
/*
* Use only 'disable' or only 'enable', those configurations exclude each other
*/
android {
lintOptions {
// use this line to check all rules except those listed
disable 'RuleToDisable', 'SecondRuleToDisable'
// use this line to check just listed rules
enable 'FirstRuleToCheck', 'LastRuleToCheck'
}
}
这篇关于gradle build 在 lint 任务上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:gradle build 在 lint 任务上失败
基础教程推荐
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
