【问题标题】:Retrofit detected an unsupported OkHttp on the classpath error in OKHttp 2.0Retrofit 在 OKHttp 2.0 的类路径错误中检测到不支持的 OkHttp
【发布时间】:2014-07-30 01:42:07
【问题描述】:

我在我的项目中使用Retrofit-1.6.0 + okhttp-2.0.0-RC1。 当我运行项目时,我得到了错误。

java.lang.RuntimeException: Retrofit detected an unsupported OkHttp on the classpath.
To use OkHttp with this version of Retrofit, you'll need:
1. com.squareup.okhttp:okhttp:1.6.0 (or newer)
2. com.squareup.okhttp:okhttp-urlconnection:1.6.0 (or newer)
Note that OkHttp 2.0.0+ is supported!

有人知道如何解决这个问题吗?

【问题讨论】:

    标签: android retrofit okhttp


    【解决方案1】:

    即使使用 OkHTTP 2,您也需要额外导入 urlConnection

    compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'

    【讨论】:

      【解决方案2】:

      好的,Square 已经在 github 上发布了 2.0 RC2,但在 maven 上没有:

      https://github.com/square/okhttp

      但你仍然需要 okhttp-urlconnection (RC1),它只在 maven 上:

      http://mvnrepository.com/artifact/com.squareup.okhttp

      别忘了 okhttp 2.0 现在依赖于 okio:

      https://github.com/square/okio

      【讨论】:

      • 请您告诉我添加 okhttp 和改造的好处是什么,因为改造即使没有 okhttp 也可以工作?
      【解决方案3】:

      我有 picasso/Retrofit 和你一样抱怨。此配置对我有用:

      compile 'com.squareup.retrofit:retrofit:1.9.0'
      compile 'com.squareup.okhttp:okhttp:2.0.0'
      compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
      compile 'com.squareup.picasso:picasso:2.5.2'
      

      【讨论】:

      • 实际上,如果您使用的是改造 1.9.0,则 不需要导入 'okhttp-urlconnection:2.0.0'如果您使用 OkHttp,则必须使用 2.0 或更高版本,并且不再需要使用 okhttp-urlconnection shim。 Retrofit 1.9.0 CHANGELOG
      • @Ryan 我可以确认我在使用改造 1.9.0 时遇到 EOFError,在导入改造 1.9.0+okhttp2.3+okhttp-urlconnection2.3 后不再出现。这个错误刚刚发生在我身上,在三星 SIII 上
      猜你喜欢
      • 2014-07-30
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 2017-05-25
      • 1970-01-01
      • 1970-01-01
      • 2017-10-10
      • 1970-01-01
      相关资源
      最近更新 更多