Giter Site home page Giter Site logo

java.lang.NoSuchMethodError about rxandroid HOT 17 OPEN

13man avatar 13man commented on August 16, 2024 3
java.lang.NoSuchMethodError

from rxandroid.

Comments (17)

huihui4045 avatar huihui4045 commented on August 16, 2024

我也是同样的问题

from rxandroid.

huihui4045 avatar huihui4045 commented on August 16, 2024

I have the same problem

from rxandroid.

huihui4045 avatar huihui4045 commented on August 16, 2024

Caused by: java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.art/javalib/core-oj.jar)
at io.reactivex.rxjava3.android.schedulers.AndroidSchedulers.(AndroidSchedulers.java:33)
at io.reactivex.rxjava3.android.schedulers.AndroidSchedulers.from(AndroidSchedulers.java:55)

from rxandroid.

JakeWharton avatar JakeWharton commented on August 16, 2024

That is not the same problem. You need to enable Java 8 support: https://developer.android.com/studio/write/java8-support#supported_features

from rxandroid.

blankyn avatar blankyn commented on August 16, 2024

问题解决了吗

from rxandroid.

Goooler avatar Goooler commented on August 16, 2024

问题解决了吗

android {
    ...
    // Configure only for each module that uses Java 8
    // language features (either in its source code or
    // through dependencies).
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    // For Kotlin projects
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

from rxandroid.

blankyn avatar blankyn commented on August 16, 2024

问题解决了吗

android {
    ...
    // Configure only for each module that uses Java 8
    // language features (either in its source code or
    // through dependencies).
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    // For Kotlin projects
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

我设置了,但是无效,依然还会报错

from rxandroid.

Goooler avatar Goooler commented on August 16, 2024

@blankyn 升级 AGP 看看,可能太旧了

from rxandroid.

blankyn avatar blankyn commented on August 16, 2024

@blankyn 升级 AGP 看看,可能太旧了

我用的3.6.3版本

from rxandroid.

blankyn avatar blankyn commented on August 16, 2024

@blankyn 升级 AGP 看看,可能太旧了

经过测试,as运行没这个问题,但是打包apk就有这个问题。rxandroid 用2.1.1的也可以,唯独升级后有问题

from rxandroid.

13man avatar 13man commented on August 16, 2024

from rxandroid.

blankyn avatar blankyn commented on August 16, 2024

此处要改成: .addCallAdapterFactory(RxJava3CallAdapterFactory.createSynchronous())

------------------ 原始邮件 ------------------ 发件人: "ReactiveX/RxAndroid" @.>; 发送时间: 2021年10月13日(星期三) 下午2:06 @.>; 抄送: "自由 @.@.>; 主题: Re: [ReactiveX/RxAndroid] java.lang.NoSuchMethodError (#578) @blankyn 升级 AGP 看看,可能太旧了 经过测试,as运行没这个问题,但是打包apk就有这个问题。rxandroid 用2.1.1的也可以,唯独升级后有问题 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

没用的,安卓部分机器有问题,我测试过,目前发现两款机器

from rxandroid.

13man avatar 13man commented on August 16, 2024

from rxandroid.

hanlyjiang avatar hanlyjiang commented on August 16, 2024

I had this problem too, and finally I found the problem.

The scenario where the problem occurs is:

  • I have a library project and an app project, and I package the library project as an aar, and then introduce it into the app project. The library project uses the static method (disposed) of the Disposable interface of rxjava3.
  • The problem only occurs when aar is introduced and the app project is packaged as an apk to manually install and run to the device. If you directly depend on the library project, or run it directly with AndroidStudio (whether it is aar dependency or project dependency), there is no problem.

I found two ways to solve or circumvent this problem:

  1. Change the way to import aar。

from:

    implementation(name:"libs",ext: "aar")

to:

    implementation(files("libs/libs.aar"))
  1. Add a property to gradle.properties
android.enableDexingArtifactTransform.desugaring=false

The cause of the problem lies in the process of desugaring.
When you look at the Dex file in the apk, you can find that the Disposable interface of rxjava3 will be divided into two parts, one of which is Disposable, which contains the declarations of two interface methods, and the other is Disposable$-CC , which contains all static methods. Our code calls static methods through Disposable, so the correct situation should be that when the class in our aar is converted to dex, the call to the static method needs to be replaced with Disposable$-CC.xxxx(), but when we aar is imported with (name,ext) , AGP will not do this for us.

More specific reasons require us to study the behavior of AGP or D8

from rxandroid.

hsy719007146 avatar hsy719007146 commented on August 16, 2024

from rxandroid.

hsy719007146 avatar hsy719007146 commented on August 16, 2024

from rxandroid.

hsy719007146 avatar hsy719007146 commented on August 16, 2024

from rxandroid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.