问题
I'm fairly new to Android, Android Studio, Butterknife and the Gradle build system. However, I'm not new to Java, or programming in general.
I'm trying to build an Android app with JDK 1.8 and Butterknife version 8.1.0 , but the Gradle build keeps failing, saying:
Error:Could not find property 'options' on task ':app:compileDebugJavaWithJack'.
Note: My project was working perfectly fine with JDK 1.8 (except for the "Instant Run" functionality) until I tried adding Butterknife.
I've already researched a bit on this, and went through the following pages/articles, but couldn't get a definitive answer the question whether Butterknife 8.1.0 works with JDK 8 or not:
- GitHub Butterknife Issue #571
- New Jack toolchain crashes when using android-apt plugin
- Android issue 203850 on Google Code
Does it work at all? If yes, what do I need to do to get it working?
Below are the details of my projects setup, and snippets from the Gradle build files. I'd be happy to provide any additional details/files that might be needed.
Version Details:
- JDK 1.8.0_92 (64 bit)
- Android Studio 2.1.2
- Gradle 2.1.2
build.gradle (Project level)
// 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 (Module level)
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'
}
SOLUTION UPDATED
By following Jake's answer, I could get Butterknife 8.1.0 to work with JDK 8 in AS 2.1.2 by making the following changes in the two build.gradle files:
build.gradle (Project level)
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-alpha5'
}
build.gradle (Module level)
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'
}
回答1:
If you are using Jack:
- Omit the 'android-apt' plugin completely.
- Use
annotationProcessor
for the dependency (instead ofapt
).
I believe you have to be using version 2.2.0 of the Android Gradle plugin though instead of 2.1.x (currently the latest is 2.2.0-alpha5).
The Butter Knife documentation will be updated for the next release (8.2.0) to include this information.
来源:https://stackoverflow.com/questions/38274453/butterknife-8-1-0-not-working-with-jdk-1-8-in-android-studio-2-1-2