Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when trying to call a suspend method within rxSingle {} #3221

Closed
ravi-paystack opened this issue Mar 18, 2022 · 1 comment
Closed

Crash when trying to call a suspend method within rxSingle {} #3221

ravi-paystack opened this issue Mar 18, 2022 · 1 comment

Comments

@ravi-paystack
Copy link

ravi-paystack commented Mar 18, 2022

Hi,

I am getting a crash when I try to call a suspend method from an rx chain. The rx chain previously had a method that was returning Single<SomeType> which is now changed to a suspend method. But when I use rxSingle to change the behavior to return Single , it crashes with the following log,

java.lang.NoSuchMethodError: No direct method <init>(Lkotlin/coroutines/CoroutineContext;Z)V in class Lkotlinx/coroutines/AbstractCoroutine; or its super classes (declaration of 'kotlinx.coroutines.AbstractCoroutine' appears in /data/app/com.paystack.pos.staging-3/base.apk:classes18.dex)
        at kotlinx.coroutines.rx2.RxSingleCoroutine.<init>(RxSingle.kt:56)
        at kotlinx.coroutines.rx2.RxSingleKt$rxSingleInternal$1.subscribe(RxSingle.kt:48)
        at io.reactivex.internal.operators.single.SingleCreate.subscribeActual(SingleCreate.java:39)
        at io.reactivex.Single.subscribe(Single.java:3603)
        at io.reactivex.internal.operators.single.SingleFlatMap.subscribeActual(SingleFlatMap.java:36)
        at io.reactivex.Single.subscribe(Single.java:3603)
        at io.reactivex.Single.subscribeWith(Single.java:3650)

I tried to do this in a test and it crashed with the same reason as above.

suspend fun sayHello(): String {
        delay(1000)
        return "Hello"
    }

    fun sayHelloSingle(): Single<String> = rxSingle { sayHello() }

    @Test
    fun testSingle(){

        sayHelloSingle().test().assertValue("Hello")
    }

Not sure what I am doing wrong. I am using version 1.4.3 for both org.jetbrains.kotlinx:kotlinx-coroutines-rx2 and org.jetbrains.kotlinx:kotlinx-coroutines-core and version 2.2.10 for rxJava. Thank you for the help 🙏🏼

@qwwdfsad
Copy link
Member

Hi, it seems like you have mismatched versions of kotlinx-coroutine-rx2 and kotlinx-coroutines-core. It's likely that higher version comes from some dependency transitively and wins gradle dependency resolution.
./gradlew :yourTask --scan can provide an additional insight for you.

There are multiple options:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants