java - Android 库模块中的 Lambda 表达式不起作用

标签 java android lambda android-service

我有一个 android 应用程序模块,它使用 jdk 8 并启用了 Jack Options。然后我将它转换为 Android 库模块。然后我必须从构建 gradle 中删除 Jack Options。现在,当我尝试构建 AAR 文件时,Lambda 表达式给出了以下错误。

Error:(59, 25) error: cannot find symbol method metafactory(Lookup,String,MethodType,MethodType,MethodHandle,MethodType)

给出这个错误的代码是,

Runnable r= () -> {
      appManager.startApp(definition,identifier);
};

我的构建 Gradle 是

Apply plugin: 'com.android.library'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

这个问题是什么原因造成的?

最佳答案

在我的机器上,我丢失了文件 $ANDROID_SDK/build-tools/28.0.3/core-lambda-stubs.jar,所以我不得不重新安装版本 28.0.3 的构建工具使用 Android Studio SDK 管理器。

(我必须选中“显示包详细信息”才能查看构建工具版本的完整列表)

关于java - Android 库模块中的 Lambda 表达式不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45452827/

相关文章:

java - 尽管请求中存在 Accept-Encoding header ,但 POST 响应未压缩

java - 将数据存储在动态二维数组中

javascript - IBM Worklight 6.1 - 如果处于脱机模式,则不会调用 NativePage.show 回调

android - 如何以编程方式减少操作栏选项卡的宽度

android - 错误 :Jack is required to support java 8 language features. 启用 Jack 或删除 sourceCompatibility JavaVersion.VERSION_1_8

javascript - ES6 传递函数作为参数示例

java - Hadoop Mapreduce 多个输入文件

java - 使用 Spring Integration 时抛出不同的 JSchException

android - 清除安卓缓存

实现匿名函数的匿名接口(interface)的java语法