本文介绍了gradle 构建在 lint 任务上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Android Studio 0.4.0 创建的简单 android 项目.我使用 Gradle 1.9 和 Gradle Android 插件 0.7.昨天我在我的 gradle 构建脚本中添加了 Jake Wharton 的 ButterKnife 库:

依赖项{编译'com.android.support:support-v4:19.0.0'编译'com.android.support:appcompat-v7:19.0.0'//牛油刀编译'com.jakewharton:butterknife:4.0.1'}

当我从 Android Studio 运行应用程序时,构建运行良好并在我的设备上正确执行.但是当我(从命令行)尝试 gradle build 时,构建失败.这是我的 lint 报告的一部分:

InvalidPackage:Android 中不包含的包/home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar中的包引用无效未包含在 Android 中:javax.annotation.processing.引用自 butterknife.internal.InjectViewProcessor./home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar中的包引用无效未包含在 Android 中:javax.annotation.processing.引用自 butterknife.internal.InjectViewProcessor./home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar中的包引用无效未包含在 Android 中:javax.annotation.processing.引用自 butterknife.internal.InjectViewProcessor./home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar中的包引用无效未包含在 Android 中:javax.annotation.processing.引用自 butterknife.internal.InjectViewProcessor./home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar中的包引用无效未包含在 Android 中:javax.annotation.processing.引用自 butterknife.internal.InjectViewProcessor.

也许我遗漏了一些东西,但无法在终端块中构建项目为 Android 项目提供 CI 的可能性.

任何帮助都会很棒.

解决方案

0.7.0 提供了对 Lint 的扩展支持,但是,它并不总是正常工作.(例如,黄油刀库)

解决方案是在发现 lint 错误时禁用中止构建

我的灵感来自https://android.googlesource.com/platform/tools/base/+/e6a5b9c7c1bca4da402de454231a/p>

(实现: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 {//你的构建配置默认配置 { ... }签名配置 { ... }编译选项 { ... }构建类型 { ... }//这很重要,它将运行 lint 检查但不会中止构建lintOptions {abortOnError false}}

如果您只需要禁用特定的 Lint 规则并保持其他人的构建失败,请使用:

/** 仅使用禁用"或启用",这些配置相互排斥*/安卓 {lintOptions {//使用这一行检查除列出的规则之外的所有规则禁用RuleToDisable"、SecondRuleToDisable"//使用这一行检查刚刚列出的规则启用FirstRuleToCheck"、LastRuleToCheck"}}

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'
}

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.

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.

Any help would be great.

解决方案

With 0.7.0 there comes extended support for Lint, however, it does not work always properly. (Eg. the butterknife library)

Solution is to disable aborting build on found lint errors

I took the inspiration fromhttps://android.googlesource.com/platform/tools/base/+/e6a5b9c7c1bca4da402de442315b5ff1ada819c7

(implementation:https://android.googlesource.com/platform/tools/base/+/e6a5b9c7c1bca4da402de442315b5ff1ada819c7/build-system/gradle/src/main/groovy/com/android/build/gradle/internal/model/DefaultAndroidProject.java )

(discussion: 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
  }
}


And if you need to disable just particular Lint rule and keep the build failing on others, use this:

/*
 * 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 构建在 lint 任务上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 23:55