lint任务上的gradle构建失败

时间:2013-12-20 08:22:51

标签: android gradle android-gradle

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

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时,构建失败。这是我的皮棉报告中的一部分:

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.

也许我错过了一些东西,但是无法在终端中构建项目阻止了Android项目CI的可能性。

任何帮助都会很棒。

11 个答案:

答案 0 :(得分:140)

0.7.0 会扩展对Lint的支持,但是,它始终无法正常工作。 (例如,奶油刀库)

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

我从中获取灵感 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'
  }
}

答案 1 :(得分:51)

如果abortOnError false无法解决您的问题,您可以试试这个。

lintOptions {
    checkReleaseBuilds false
}

答案 2 :(得分:27)

您可以从此处选择适当的选项

android {
    lintOptions {
        // set to true to turn off analysis progress reporting by lint
        quiet true
        // if true, stop the gradle build if errors are found
        abortOnError false
        // if true, only report errors
        ignoreWarnings true
        // if true, emit full/absolute paths to files with errors (true by default)
        //absolutePaths true
        // if true, check all issues, including those that are off by default
        checkAllWarnings true
        // if true, treat all warnings as errors
        warningsAsErrors true
        // turn off checking the given issue id's
        disable 'TypographyFractions','TypographyQuotes'
        // turn on the given issue id's
        enable 'RtlHardcoded','RtlCompat', 'RtlEnabled'
        // check *only* the given issue id's
        check 'NewApi', 'InlinedApi'
        // if true, don't include source code lines in the error output
        noLines true
        // if true, show all locations for an error, do not truncate lists, etc.
        showAll true
        // Fallback lint configuration (default severities, etc.)
        lintConfig file("default-lint.xml")
        // if true, generate a text report of issues (false by default)
        textReport true
        // location to write the output; can be a file or 'stdout'
        textOutput 'stdout'
        // if true, generate an XML report for use by for example Jenkins
        xmlReport false
        // file to write report to (if not specified, defaults to lint-results.xml)
        xmlOutput file("lint-report.xml")
        // if true, generate an HTML report (with issue explanations, sourcecode, etc)
        htmlReport true
        // optional path to report (default will be lint-results.html in the builddir)
        htmlOutput file("lint-report.html")

        // set to true to have all release builds run lint on issues with severity=fatal
        // and abort the build (controlled by abortOnError above) if fatal issues are found
        checkReleaseBuilds true
        // Set the severity of the given issues to fatal (which means they will be
        // checked during release builds (even if the lint target is not included)
        fatal 'NewApi', 'InlineApi'
        // Set the severity of the given issues to error
        error 'Wakelock', 'TextViewEdits'
        // Set the severity of the given issues to warning
        warning 'ResourceAsColor'
        // Set the severity of the given issues to ignore (same as disabling the check)
        ignore 'TypographyQuotes'
    }
}

答案 3 :(得分:15)

我在Android Studio中遇到了一些lint错误,只有在我生成签名的APK时才会出现。

为避免这种情况,我将以下内容添加到build.gradle

android {
    lintOptions {
        checkReleaseBuilds false
    }
}

答案 4 :(得分:11)

将这些行添加到build.gradle文件中:

android { 
  lintOptions { 
    abortOnError false 
  }
}

然后清理您的项目:D

答案 5 :(得分:8)

如果你想避免" abortInError false"选项,看看build / lint-results-release-fatal.html文件。以下是lint检测到的错误。

我希望这可以帮助别人!

答案 6 :(得分:4)

在Android Studio v1.2中,它会告诉您如何修复它:

enter image description here

答案 7 :(得分:3)

在AndroidStudio版本0.51上出现相同的错误

Build工作正常,突然,只更改了版本代码值后,我得到了一个与Lint相关的构建错误。

尝试更改build.gradle,清除AndroidStudio缓存并重新启动,但没有更改。

最后,我返回原始代码(导致错误),并从android:debuggable="false"中删除了AndroidManifest.xml,导致构建成功。

我再次添加它仍然有效...不要问我为什么:S

答案 8 :(得分:2)

至于我,这是一个糟糕而快速的问题解决方案:

android { 
  lintOptions { 
    abortOnError false 
  }
}

更好的解决方案正在解决您的代码中的问题,因为lint工具会检查您的Android项目源文件是否存在潜在错误,并针对正确性,安全性,性能,可用性,可访问性和国际化进行了优化改进。

最常出现的问题

  • 布局包含未解析的符号或缺少某些属性
  • 其他结构性问题(例如使用目标API版本不支持的已弃用元素或API调用)可能会导致代码无法正常运行。

在Android Studio中Inspect Code找出您的错误:Improve Your Code with Lint

答案 9 :(得分:1)

添加

android.lintOptions.abortOnError false

到你的app \ build.gradle

答案 10 :(得分:0)

如果您设置了 abortOnError false,您将看到警告:

<块引用>

无法访问“abortOnError”:它在“LintOptions”中是私有的

enter image description here

感谢 erluxman,您只需在 lintOptions {} 块内的空白处按 Ctrl+Space 即可查看属性并写入:

lintOptions {
    // if true, stop the gradle build if errors are found
    isAbortOnError = false
    // if true, show all locations for an error, do not truncate lists, etc.
    isShowAll = true
}