首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用AndroidStudio3.0 Java 8内置特性替换Retrolambda

用AndroidStudio3.0 Java 8内置特性替换Retrolambda
EN

Stack Overflow用户
提问于 2017-05-19 11:01:40
回答 1查看 3.8K关注 0票数 15

在我的项目中,我使用了流行的库retrolambda。我刚刚下载了新的AndroidStudio3.0金丝雀1。

我已经更新了我的项目,使用新版本的Gradle等,一切都很好。

Android 3中的新功能是为了支持一些Java8特性而构建的。新的AS3建议删除retrolambda并使用这些特性。

我已经删除了retrolambda,Gradle构建是成功的,但是应用程序由于这个错误而崩溃了(在有lambda的地方)

代码语言:javascript
复制
E/UncaughtException: java.lang.NoSuchMethodError: No static method lambda$replace$2

我在我的项目中使用RxJava2。我不确定这是否与它有关,但在我的例子中,Java8的内置特性不起作用。也许我需要在“某个地方”放点东西?

我的项目设置

我的分级文件

根工程

代码语言:javascript
复制
   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'
    }

App模块

代码语言:javascript
复制
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'
EN

回答 1

Stack Overflow用户

发布于 2017-07-06 14:10:06

这可能是由于在https://issuetracker.google.com/issues/62456849中跟踪的Gradle Java 8语言特性中的一个bug造成的。

desugar似乎盲目地重命名了类文件中的合成方法,如果它们的名称以lambda$ (追加所有者类名)开头,而不管字节码中是否已经存在对该方法的引用(并且引用也不会被重命名)。

当代码路径在运行时碰到这样的引用时,明显的结果是一个NoSuchMethodError,因为这个名称的方法已经不存在了。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44068347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档