Android Jack:来自jar文件的Lambda需要在类路径上编译接口,未知接口是java.util.function.Consumer

Ray*_*yek 17 java lambda android android-studio

在Android studio 2.2上获取此功能.

有没有人有解决方法?

我的应用构建文件是:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "acme.cb2"
        minSdkVersion 18
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        jackOptions {
            enabled true
        }

    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:support-v4:24.1.1'
}
Run Code Online (Sandbox Code Playgroud)

编辑:修改构建文件以包含来自/sf/users/402716401/的答案- 但这没有帮助

import java.text.SimpleDateFormat

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
        classpath 'org.hidetake:gradle-ssh-plugin:2.4.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xbootclasspath/a:" + System.properties.get("java.home") + "/lib/rt.jar"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:添加:

options.compilerArgs.each { println 'option: '+it}
Run Code Online (Sandbox Code Playgroud)

打印出来:

option: -Xbootclasspath/a:C:\Program Files\Java\jdk1.8.0_92\jre/lib/rt.jar
Run Code Online (Sandbox Code Playgroud)

看起来路径中的空间可能会导致问题?

编辑:尝试:

options.compilerArgs << "\""+"-Xbootclasspath/a:" + System.properties.get("java.home") + "/lib/rt.jar"+"\""
Run Code Online (Sandbox Code Playgroud)

也不起作用.

moh*_*feh 0

将其添加到您的 build.gradle 中:

allprojects {
    repositories {
        jcenter()
    }
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xbootclasspath/a:" + System.properties.get("java.home") + "/lib/rt.jar"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)