Cannot access class 'okhttp3.ResponseBody'. Check your module classpath for missing or conflicting dependencies
这是我的职责:
fun parseError(httpException: HttpException) {
val errorBody = httpException.response()?.errorBody()
}
这些是我包含的依赖项
implementation("com.squareup.okhttp3:okhttp:4.11.0")
implementation("com.squareup.moshi:moshi-kotlin:1.15.0")
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-moshi:2.9.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.11.0")
这是图像,您可以看到
errorBody()
下方有一个错误
您缺少一个具有 OkHttp3.ResponseBody 类的依赖项
implementation 'com.squareup.okhttp3:okhttp:{latest_version}'
希望这有帮助
编辑答案;
我发现这个改造的2.9.0版本有问题。更新到2.8.2版本后将会修复。
version.retrofit2=2.8.2
您可以通过执行2.8.2来使用它。
旧答案;
我认为你的项目是多模块的。你可以尝试使用“api”而不是“implementation”吗?
我发表此评论是因为我看不到更多细节。
找不到相关依赖的原因是依赖 作为我们项目的参考,暴露了对其的第三方依赖 API 表面。