Skip to content

java.lang.NoSuchMethodError #578

Open

Description

@13man

OkHttp Dispatcher(48197)

java.lang.NoSuchMethodError

No static method disposed()Lio/reactivex/rxjava3/disposables/Disposable; in class Lio/reactivex/rxjava3/disposables/Disposable; or its super classes (declaration of 'io.reactivex.rxjava3.disposables.Disposable' appears in base.apk!classes3.dex)

1 io.reactivex.rxjava3.android.schedulers.HandlerScheduler$HandlerWorker.schedule(HandlerScheduler.java:91)

2 io.reactivex.rxjava3.core.Scheduler$Worker.schedule(Scheduler.java:402)
3 io.reactivex.rxjava3.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.schedule(ObservableObserveOn.java:161)
4 io.reactivex.rxjava3.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.onComplete(ObservableObserveOn.java:139)
5 io.reactivex.rxjava3.internal.operators.observable.ObservableSubscribeOn$SubscribeOnObserver.onComplete(ObservableSubscribeOn.java:68)
6 retrofit2.adapter.rxjava3.BodyObservable$BodyObserver.onComplete(BodyObservable.java:70)
7 retrofit2.adapter.rxjava3.CallEnqueueObservable$CallCallback.onResponse(CallEnqueueObservable.java:66)
8 retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:161)
9 okhttp3.RealCall$AsyncCall.run(RealCall.kt:138)
10 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
11 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
12 java.lang.Thread.run(Thread.java:929)

What is the problem and how to solve it ?

Activity

  1. huihui4045 commented on Apr 22, 2021

    @huihui4045
  2. huihui4045 commented on Apr 22, 2021

    @huihui4045
  3. huihui4045 commented on Apr 22, 2021

    @huihui4045
  4. JakeWharton commented on Apr 22, 2021

    @JakeWharton
  5. blankyn commented on Oct 9, 2021

    @blankyn

    问题解决了吗

  6. Goooler commented on Oct 9, 2021

    @Goooler
    Contributor

    问题解决了吗

    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"
        }
    }
    
  7. blankyn commented on Oct 13, 2021

    @blankyn

    问题解决了吗

    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"
        }
    }
    

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

  8. Goooler commented on Oct 13, 2021

    @Goooler
    Contributor

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

  9. blankyn commented on Oct 13, 2021

    @blankyn

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

    我用的3.6.3版本

  10. blankyn commented on Oct 13, 2021

    @blankyn

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

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

  11. 13man commented on Oct 13, 2021

    @13man
    Author
  12. blankyn commented on Nov 5, 2021

    @blankyn

    此处要改成: .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.

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

  13. 13man commented on Nov 5, 2021

    @13man
    Author
  14. hanlyjiang commented on Mar 9, 2022

    @hanlyjiang

    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

  15. hsy719007146 commented on Apr 27, 2022

    @hsy719007146
  16. hsy719007146 commented on Oct 11, 2022

    @hsy719007146
  17. hsy719007146 commented on Dec 22, 2022

    @hsy719007146
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions