问题描述
我有一个使用 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)
百家乐凯发k8的解决方案是在发现 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' } }