You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

搭配Retrofit 2.1.0的OkHttp及日志拦截器适配版本咨询

解决Retrofit运行时的NoSuchMethodError问题

问题根源

你遇到的java.lang.NoSuchMethodError是因为OkHttp核心库、日志拦截器与Retrofit的版本不兼容。具体来说,你使用的okhttp:3.0.0-RC1和logging-interceptor:3.0.0-RC1属于早期预览版,其中okhttp3.internal.Platform类并不包含日志拦截器需要调用的log(String)方法,而Retrofit 2.1.0依赖的是更稳定的OkHttp版本。

解决方案

将OkHttp核心库和日志拦截器的版本统一升级到与Retrofit 2.1.0适配的稳定版本,推荐使用3.3.1版本(这是Retrofit 2.1.0官方兼容的OkHttp版本)。修改你的依赖配置如下:

implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.3.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.3.1'

关键注意事项

  • 必须保证okhttp和logging-interceptor的版本完全一致,日志拦截器是OkHttp的扩展组件,版本不匹配必然会引发兼容性问题。
  • 如果后续需要升级Retrofit,也要同步升级OkHttp到对应兼容的版本(比如Retrofit 2.9.0对应OkHttp 4.x系列版本)。

内容的提问来源于stack exchange,提问作者Ouissal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:02:08