https://kotlinlang.org logo
#android
Title
# android
l

Leon K

10/16/2019, 3:52 PM
hey, I've got a problem: I'm trying to use Retrofit with the Kotlin Coroutine-integration (just make the functions in the
API
interface
suspend
and return the data directly, without being wrapped in
Call
) but as soon as i try to do this, i get
java.lang.IllegalArgumentException: Could not locate call adapter for class java.lang.Object.
any ideas? if i use the
Call
wrapped way it works
d

Dustin Lam

10/16/2019, 4:19 PM
Make sure you're using retrofit 2.6.0+
As it wasn't added until then I believe
g

gildor

10/16/2019, 11:07 PM
Could you show declaration of this Retrofit method
CallAdapter is not needed for Coroutines and suspend functions, now it's part of core Retrofit
d

Dustin Lam

10/16/2019, 11:09 PM
Oh you're right - my mistake!
u

ursus

10/18/2019, 3:14 AM
@gildor why is that? what if I only want to use rx
g

gildor

10/18/2019, 3:16 AM
why is that
I didn’t get your question. Retrofit supports suspend functions out of the box now, no need to have any adapters. Rx requires adapter
d

Dustin Lam

10/18/2019, 3:18 AM
I think he means he shouldnt have to take the coroutines dependency if he is using rx
g

gildor

10/18/2019, 3:25 AM
No, suspend function is part of Kotlin itself and stdlib, it has nothing to do with kotlinx.coroutines. And because Retrofit is written now in Kotlin you anyway have dependency on Kotlin stdlib
d

Dustin Lam

10/18/2019, 3:31 AM
kotlinx.coroutines is an optional dependency of retrofit
g

gildor

10/18/2019, 3:32 AM
Yes, it’s optional, to support cancellation and provide
Call.await()
3 Views