【发布时间】: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 的问题:
- GitHub Butterknife Issue #571
- New Jack toolchain crashes when using android-apt plugin
- Android issue 203850 on Google Code
它真的有效吗?如果是,我需要做什么才能使其正常工作?
以下是我的项目设置的详细信息,以及 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