問題描述
我有一個使用 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模板網!