android - 错误 :Lambda coming from jar file need their interfaces on the classpath to be compiled RxJava2

标签 android lambda java-8 rx-java2 jack-compiler

我正在使用 RxJava2 和 lambda。 IDE是Android Studio。编译时出现以下错误。

信息:Gradle 任务:generateDebugAndroidTestSources, :transport:mockableAndroidJar, :transport:prepareDebugUnitTestDependencies, :transport:compileDebugSources, :transport:compileDebugAndroidTestSources, :transport:compileDebugUnitTestSources]

错误:来自 jar 文件的 Lambda 需要编译类路径上的接口(interface),未知接口(interface)是 io.socket.emitter.Emitter$Listener

错误:来自 jar 文件的 Lambda 需要编译它们在类路径上的接口(interface),未知接口(interface)是 io.reactivex.functions.Predicate

错误:来自 jar 文件的 Lambda 需要编译类路径上的接口(interface),未知接口(interface)是 io.reactivex.functions.Consumer

错误:来自 jar 文件的 Lambda 需要编译类路径上的接口(interface),未知接口(interface)是 io.socket.emitter.Emitter$Listener

错误:来自 jar 文件的 Lambda 需要编译类路径上的接口(interface),未知接口(interface)是 io.socket.emitter.Emitter$Listener

错误:来自 jar 文件的 Lambda 需要编译它们在类路径上的接口(interface),未知接口(interface)是 io.reactivex.FlowableOnSubscribe

错误:来自 jar 文件的 Lambda 需要编译类路径上的接口(interface),未知接口(interface)是 io.socket.emitter.Emitter$Listener

错误:来自 jar 文件的 Lambda 需要编译类路径上的接口(interface),未知接口(interface)是 io.socket.emitter.Emitter$Listener

错误:任务 ':app:transformClassesWithPreJackPackagedLibrariesForDebug' 执行失败。

com.android.build.api.transform.TransformException: com.android.builder.core.JackToolchain$ToolchainException: Jack compilation exception

按照我的 build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
    applicationId "com.communicator"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
    jackOptions {
        enabled true
    }

    }
    buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    }
    configurations.all {
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }
}

ext {
    rxlifecycleVersion = '2.0.1'
    icepickVersion = '3.2.0'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'io.reactivex.rxjava2:rxjava:2.0.7'
    compile "com.trello.rxlifecycle2:rxlifecycle:$rxlifecycleVersion"
    compile "com.trello.rxlifecycle2:rxlifecycle-android:$rxlifecycleVersion"
    compile "com.trello.rxlifecycle2:rxlifecycle-components:$rxlifecycleVersion"

    compile "frankiesardo:icepick:$icepickVersion"
    provided "frankiesardo:icepick-processor:$icepickVersion"

    compile project(path: ':transport')
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:design:25.3.1'
    testCompile 'junit:junit:4.12'
}

以下顺序有效。

  1. 将 minSdkVersion 更改为 25。同步并制作项目。
  2. 再次将 minSdkVersion 更改为 15。同步并制作项目。

但这会使编译变得非常缓慢,每次更改代码后我都需要遵循此顺序。有更好的选择吗?

最佳答案

它与 android-gradle 支持有关。 您可能必须使用新版本的 android gradle 插件,但到目前为止它有点棘手。

我使用 gradle-android 插件版本 2.4.0-alpha7 解决了同样的问题

在 build.gradle 中我添加了:

classpath 'com.android.tools.build:gradle:2.4.0-alpha7'

然而,仅此还不够,还需要一个环境变量(因为它是 alpha 版本),参见 this answer

关于android - 错误 :Lambda coming from jar file need their interfaces on the classpath to be compiled RxJava2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43434529/

相关文章:

java - 为什么接口(interface)的泛型方法可以在 Java 中实现为非泛型?

android - 如何制作单个 AAR 文件,有一些其他 AAR 文件

c++ - 参数列表中没有 "const"无法编译 lambda

android - 谷歌播放控制台 : How to promote Android app from Alpha to Beta

java - 将对象(包括 lambda)转换为 JSON,反之亦然

c++ - 在 C++0x 中专门针对 lambda 模板

sql-server-2005 - com/microsoft/sqlserver/jdbc/SQLServerDriver 已由更新版本的 Java 运行时编译

java - 不可分割的分离器

Android 使用 JSoup 解析 html 表格

java - 如何在 Android map 中使用 2 点确定 vector ?