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

拈花ヽ惹草 提交于 2020-07-15 15:16:07

问题


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...


回答1:


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

com.squareup.retrofit2:converter-moshi:2.5.1-SNAPSHOT



回答2:


You need update retrofit, version > 2'6



来源:https://stackoverflow.com/questions/56201771/kotlin-coroutines-suspend-fun-retrofit-throws-no-retrofit-annotation-found-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!