微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Butterknife 8.1.0在Android Studio 2.1.2中不能与JDK 1.8一起使用

我是 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’.

注意:我的项目与JDK 1.8完全正常(除了“即时运行”功能),直到我尝试添加Butterknife.

我已经对此进行了一些研究,并浏览了以下几页/文章,但无法明确回答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构建文件中的代码段.
我很乐意提供可能需要的任何其他详细信息/文件.

版本细节:

> 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)中更新,以包含此信息.

原文地址:https://www.jb51.cc/android/317430.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐