Butterknife 8.1.0 在 Android Studio 2.1.2 中无法与 JDK 1.8 一起使用
Butterknife 8.1.0 not working with JDK 1.8 in Android Studio 2.1.2
我是 Android、Android Studio、Butterknife 和 Gradle 构建系统的新手。但是,我对 Java 或一般编程并不陌生。
我正在尝试使用 JDK 1.8 和 Butterknife 版本 8.1.0 构建一个 Android 应用程序,但是 Gradle 构建一直失败,说:
Error:Could not find property 'options' on task
':app:compileDebugJavaWithJack'.
注意:在我尝试添加 Butterknife 之前,我的项目在 JDK 1.8 上运行得非常好("Instant Run" 功能除外)。
我已经对此进行了一些研究,并经历了以下 pages/articles,但无法得到 Butterknife 8.1.0 是否适用于 JDK 8 或不是:
- GitHub Butterknife Issue #571
- New Jack toolchain crashes when using android-apt plugin
- Android issue 203850 on Google Code
它真的有效吗?如果是,我需要做什么才能使其正常工作?
下面是我的项目设置的详细信息,以及来自 Gradle 构建文件的片段。
我很乐意提供可能需要的任何其他 details/files。
版本详情:
- 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-apt' 插件。
- 使用
annotationProcessor
作为依赖项(而不是 apt
)。
我相信您必须使用 Android Gradle 插件的 2.2.0 版而不是 2.1.x(目前最新的是 2.2.0-alpha5) .
Butter Knife 文档将在下一版本 (8.2.0) 中更新以包含此信息。
我是 Android、Android Studio、Butterknife 和 Gradle 构建系统的新手。但是,我对 Java 或一般编程并不陌生。
我正在尝试使用 JDK 1.8 和 Butterknife 版本 8.1.0 构建一个 Android 应用程序,但是 Gradle 构建一直失败,说:
Error:Could not find property 'options' on task ':app:compileDebugJavaWithJack'.
注意:在我尝试添加 Butterknife 之前,我的项目在 JDK 1.8 上运行得非常好("Instant Run" 功能除外)。
我已经对此进行了一些研究,并经历了以下 pages/articles,但无法得到 Butterknife 8.1.0 是否适用于 JDK 8 或不是:
- GitHub Butterknife Issue #571
- New Jack toolchain crashes when using android-apt plugin
- Android issue 203850 on Google Code
它真的有效吗?如果是,我需要做什么才能使其正常工作?
下面是我的项目设置的详细信息,以及来自 Gradle 构建文件的片段。 我很乐意提供可能需要的任何其他 details/files。
版本详情:
- 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-apt' 插件。
- 使用
annotationProcessor
作为依赖项(而不是apt
)。
我相信您必须使用 Android Gradle 插件的 2.2.0 版而不是 2.1.x(目前最新的是 2.2.0-alpha5) .
Butter Knife 文档将在下一版本 (8.2.0) 中更新以包含此信息。