【问题标题】:Kotlin Coroutines suspend fun + retrofit throws "No Retrofit annotation found" errorKotlin Coroutines suspend fun + retrofit 抛出“No Retrofit annotation found”错误
【发布时间】:2019-10-05 16:37:20
【问题描述】:

我正在尝试在 2.5.1-SNAPSHOT 中使用改造的协程支持,但我不断收到一个奇怪的异常。

我的改造服务类有:

@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

当我尝试调用它时,我得到:

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

这看起来很奇怪,因为错误出在参数 #5 上,但只有 4 个参数。有人见过这个吗?

另请注意,这是使用

进行调试构建
minifyEnabled false

所以我怀疑它是proguard...

【问题讨论】:

  • 我没有解决方案,但问题是因为 Kotlin 编译器将您的方法更改为采用额外的参数,用于协程继续。
  • 我已经解决了,并发布了解决方案。谢谢

标签: android kotlin retrofit coroutine


【解决方案1】:

原来你还需要转换器工厂的 SNAPSHOT 版本。

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

【讨论】:

【解决方案2】:

您需要更新改造,版本 > 2'6

【讨论】:

    猜你喜欢
    • 2020-02-24
    • 2021-08-16
    • 2020-04-25
    • 2019-12-17
    • 2020-08-03
    • 1970-01-01
    • 2016-09-09
    • 1970-01-01
    相关资源
    最近更新 更多