美文网首页长路漫漫,bug作伴
retrofit:Unable to create call a

retrofit:Unable to create call a

作者: 慕尼黑凌晨四点 | 来源:发表于2020-09-02 21:59 被阅读0次

环境:使用了retrofit2+协程
原因:Retrofit中未找到Object类相对应的CallAdapter

解决方法:

1 看callAdapterFactory是否添加正确

2 接口方法不能用suspend

interface Api{
    @GET("auth")
    suspend fun getTokenAsync(): Deferred<Bean>
}

改为

interface Api{
    @GET("auth")
   fun getTokenAsync(): Deferred<Bean>
}

原理:retrofit源码中用到动态代理,返回值类型存放在动态代理的method方法中。加了suspend关键字后method.getReturnType恒为Object类型(再问为什么我也不知道了)

retrofit相关文章

你真的会用Retrofit2吗?Retrofit2完全教程
当Retrofit遇上协程
retrofit2-kotlin-coroutines-adapter

相关文章

网友评论

    本文标题:retrofit:Unable to create call a

    本文链接:https://www.haomeiwen.com/subject/mlkvsktx.html