使用Android Studio 3.0的Java 8内置功能替换Retrolambda

15
在我的项目中,我正在使用流行的库 retrolambda 。 我刚刚下载了新的Android Studio 3.0 Canary 1。
我已经更新了我的项目以使用Gradle的新版本等。一切都没问题。
Android Studio 3中的新功能是内置对某些Java8功能的支持。 新的AS3建议删除retrolambda并使用这些功能。

Retrolambda warning

我已经移除了retrolambda,Gradle构建成功,但是应用程序在lambda表达式所在的位置崩溃并显示此错误。

E/UncaughtException: java.lang.NoSuchMethodError: No static method lambda$replace$2

我在我的项目中使用RxJava2。我不确定这是否与此有关,但在我的情况下,Java8的内置功能似乎无法正常工作。也许我需要在某个地方设置一些东西?
我的项目设置enter image description here 我的Gradle文件
根项目
   dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
        classpath 'com.google.gms:google-services:3.0.0'
        //classpath 'me.tatarka:gradle-retrolambda:3.6.1'
    }

应用程序模块

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
    }
}

repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
}


apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.hugo'

...



    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.firebase:firebase-analytics:9.8.+'
    compile 'com.google.firebase:firebase-crash:9.8.+'
    compile 'com.google.android.gms:play-services-maps:9.8.+'
    compile 'com.google.android.gms:play-services-analytics:9.8.+'
    compile 'com.google.android.gms:play-services-auth:9.8.+'
    compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
    //Support Library

(...)

    compile 'com.squareup.retrofit2:retrofit:2.2.0'
    compile 'com.squareup.retrofit2:converter-gson:2.2.0'
    compile 'com.google.maps.android:android-maps-utils:0.4'

    /* RXJAVA2 */
    compile 'io.reactivex.rxjava2:rxjava:2.0.6'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
    compile 'com.github.VictorAlbertos:ReactiveCache:1.1.0-2.x'
    compile 'com.github.VictorAlbertos.Jolyglot:gson:0.0.3'


android {


    compileSdkVersion 25
    buildToolsVersion '25.0.2'
    defaultConfig {
        applicationId "my_app_id"
        minSdkVersion 15
        targetSdkVersion 25
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

(...)

    dexOptions {
        javaMaxHeapSize "4g"
    }
    lintOptions {
        abortOnError false
    }

    }

    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
        }

        debugpro {
            minifyEnabled true
            shrinkResources false
            proguardFile file('proguard-project.txt')
            proguardFile file('proguard-google-api-client.txt')
            //noinspection GroovyAssignabilityCheck
            signingConfig signingConfigs.debug
        }

        release {
            minifyEnabled true
            shrinkResources false
            proguardFile file('proguard-project.txt')
            proguardFile file('proguard-google-api-client.txt')



        }
        releaseci {
            minifyEnabled true
            shrinkResources false
            proguardFile file('proguard-project.txt')
            proguardFile file('proguard-google-api-client.txt')
            //noinspection GroovyAssignabilityCheck
            signingConfig signingConfigs.releaseci
        }


(...)

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }




}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.jakewharton.butterknife'

请显示Gradle文件。 - Tim
@TimCastelijns 更新完成 - adek
你能展示出导致程序崩溃的代码吗? - Tim
2
RxLocation库出现了相同的错误!您能解决这个问题吗? - Mohamed ALOUANE
1
@Mohamed ALOUANE 请查看我在 https://github.com/patloew/RxLocation/issues/37 上的回答和评论。 - Stefan Zobel
显示剩余4条评论
1个回答

4
这可能是Gradle Java 8语言特性解糖中的一个错误导致的,该错误已在https://issuetracker.google.com/issues/62456849中跟踪。 desugar似乎会盲目地重命名类文件中以lambda$开头的合成方法(附加所有者类名),而不管字节码中是否已经存在对该方法的引用(该引用没有被重命名)。
当代码路径在运行时遇到这样的引用时,显然的结果是NoSuchMethodError,因为该名称的方法不再存在。

这个问题解决了吗?因为我也遇到了这个问题。这个desugaring问题的解决方案是什么?@stefanzobel - Akshay Mahajan
@Akshay Mahajan 为什么使用这么旧的版本?AS 3.0 的最终版本已经发布了一段时间。我使用的是 com.android.tools.build:gradle:3.0.0 - Stefan Zobel
我正在使用相同的 com.android.tools.build:gradle:3.0.0 和 AS 3.0,但没有帮助。我是否漏掉了什么?@stefanzobel - Akshay Mahajan
1
@Akshay Mahajan,请提出一个新问题(可以链接到此问题),并详细描述您的问题。无法从远处判断您的问题是什么。 - Stefan Zobel
让我们在聊天中继续这个讨论 - Akshay Mahajan
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接