我有一个使用 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 任务上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!