Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin Coroutines suspend fun + retrofit throws "No Retrofit annotation found" error

I'm trying to use retrofit's coroutine support in 2.5.1-SNAPSHOT but I keep getting a strange exception.

My retrofit service class has:

@GET("weather")
suspend fun getForecast(@Query("q") query: String, @Query("num_of_days") numDays: String = "1",
                @Query("format") format : String = "json", @Query("key") apiKey: String = API_KEY)
        : Weather

And when I try to call it I get:

2019-05-18 13:57:01.507 27422-27477/com.my.app  E/MainPresenter$onResume$$inlined$CoroutineExceptionHandler: Something went wrong: No Retrofit annotation found. (parameter #5)
    for method WeatherService.getForecast

Which seems odd, since the error is with parameter #5, but there are only 4 parameters. Anyone seen this before?

Also note, this is for a debug build with

minifyEnabled false

So I doubt it's proguard...

like image 911
M Dapp Avatar asked May 18 '19 18:05

M Dapp


2 Answers

Turns out you need the SNAPSHOT version of the converter factory as well.

com.squareup.retrofit2:converter-moshi:2.5.1-SNAPSHOT
like image 54
M Dapp Avatar answered Sep 25 '22 22:09

M Dapp


You need update retrofit, version > 2'6

like image 25
Andres Rivas Avatar answered Sep 21 '22 22:09

Andres Rivas