【问题标题】:Butterknife 8.1.0 not working with JDK 1.8 in Android Studio 2.1.2Butterknife 8.1.0 不适用于 Android Studio 2.1.2 中的 JDK 1.8
【发布时间】:2016-07-08 19:55:22
【问题描述】:

我对 Android、Android Studio、Butterknife 和 Gradle 构建系统还很陌生。不过,我对 Java 或一般编程并不陌生。

我正在尝试使用 JDK 1.8 和 Butterknife 版本 8.1.0 构建一个 Android 应用,但 Gradle 构建一直失败,说:

错误:在任务中找不到属性“选项” ':app:compileDebugJavaWithJack'.

注意:在我尝试添加 Butterknife 之前,我的项目在 JDK 1.8 上运行良好(“即时运行”功能除外)。

我已经对此进行了一些研究,并浏览了以下页面/文章,但无法明确回答 Butterknife 8.1.0 是否适用于 JDK 8 的问题:

它真的有效吗?如果是,我需要做什么才能使其正常工作?

以下是我的项目设置的详细信息,以及 Gradle 构建文件中的 sn-ps。 我很乐意提供可能需要的任何其他详细信息/文件。

版本详情:

  • JDK 1.8.0_92(64 位)
  • Android Studio 2.1.2
  • Gradle 2.1.2

build.gradle(项目级别)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
//        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'com.android.tools.build:gradle:2.1.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(模块级别)

apply plugin: 'com.android.application'
apply plugin: 'android-apt'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "sounakray.popularmovies"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        jackOptions {
            enabled true
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:design:24.0.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.google.code.gson:gson:2.7'
    compile 'com.jakewharton:butterknife:8.1.0'
    apt 'com.jakewharton:butterknife-compiler:8.1.0'
}

解决方案更新

按照Jake's 的回答,我可以通过在两个 build.gradle 文件中进行以下更改来让 Butterknife 8.1.0 与 AS 2.1.2 中的 JDK 8 一起使用:

build.gradle(项目级别)

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0-alpha5'
}

build.gradle(模块级别)

apply plugin: 'com.android.application'
//apply plugin: 'android-apt'
...

dependencies {
    ...
    compile 'com.jakewharton:butterknife:8.1.0'
    annotationProcessor  'com.jakewharton:butterknife-compiler:8.1.0'
}

【问题讨论】:

  • 最好更新您的 Android Studio,不要使用 Jack,它非常缓慢且已弃用

标签: android android-gradle-plugin butterknife android-studio-2.1


【解决方案1】:

如果您使用的是 Jack:

  • 完全省略“android-apt”插件。
  • 对依赖项使用annotationProcessor(而不是apt)。

我相信你必须使用 2.2.0 版的 Android Gradle 插件,而不是 2.1.x(目前最新的是 2.2.0-alpha5)。

Butter Knife 文档将在下一个版本 (8.2.0) 中更新以包含此信息。

【讨论】:

  • 非常感谢@Jake 的快速回复!您的解决方案就像一个魅力!没有什么比图书馆的创建者亲自回答更好的了! :)
  • 如果将@SounakRay 答案复制到您的项目文档页面(即github.com/codepath/android_guides/wiki/… 的设置部分)会有所帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-10
  • 2018-03-16
  • 1970-01-01
  • 1970-01-01
  • 2023-03-24
  • 1970-01-01
相关资源
最近更新 更多