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

查看:204
本文介绍了Butterknife 8.1.0不能与Android Studio 2.1.2中的JDK 1.8一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚接触Android,Android Studio,Butterknife和Gradle构建系统。但是,我对Java或一般的编程并不陌生。

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.

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

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:


错误:在任务
':app:compileDebugJavaWithJack上找不到属性'options' '。

Error:Could not find property 'options' on task ':app:compileDebugJavaWithJack'.

注意:在我尝试添加之前,我的项目在JDK 1.8上运行良好(除了 Instant Run功能)

Note: My project was working perfectly fine with JDK 1.8 (except for the "Instant Run" functionality) until I tried adding Butterknife.

我已经对此进行了一些研究,并仔细阅读了以下页面/文章,但无法确切地回答问题是否为Butterknife 8.1。 0是否与JDK 8兼容:

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?

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

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.

版本详细信息:


  • JDK 1.8.0_92(64位)

  • Android Studio 2.1.2

  • 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的答案,我可以得到Butterknife 8.1.0与AS 2.1.2中的JDK 8一起工作在两个build.gradle文件中进行以下更改:


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(项目级别)

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'
}


推荐答案

如果您使用的是Jack:

If you are using Jack:


  • 完全省略 android-apt插件。

  • 使用 annotationProcessor (而不是 apt )。

  • Omit the 'android-apt' plugin completely.
  • Use annotationProcessor for the dependency (instead of apt).

我相信您有使用的是Android Gradle插件的2.2.0版本,而不是2.1.x版本(当前是l atest是2.2.0-alpha5)。

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).

黄油刀文档将在下一个版本(8.2.0)中进行更新,以包含此信息。

The Butter Knife documentation will be updated for the next release (8.2.0) to include this information.

这篇关于Butterknife 8.1.0不能与Android Studio 2.1.2中的JDK 1.8一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆