Retrofit 2 调用失败 - 抽象方法 "void okhttp3.Callback.onResponse"

Retrofit 2 calls fail - abstract method "void okhttp3.Callback.onResponse"

我在我的项目中导入了 Retrofit,将以下内容添加到 app.gradle:

compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'

然而现在,当执行调用时,应用程序崩溃并出现以下错误:

FATAL EXCEPTION: OkHttp Dispatcher
    Process: com.my.app, PID: 31176
    java.lang.AbstractMethodError: abstract method "void okhttp3.Callback.onResponse(okhttp3.Call, okhttp3.Response)"
      at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133)
      at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:33)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
      at java.lang.Thread.run(Thread.java:818)

由于LoganSquare JSON parser,我需要导入特定版本的 Retrofit (2.0.0-beta3) 否则我会考虑使用以前版本的 Retrofit。如何解决这个问题?

问题是 Retrofit 需要特定版本的 OkHttp 库。不仅如此,如果您导入 logging-interceptor,您还需要确保正确的版本。所以,就我而言,这有帮助:

compile 'com.squareup.okhttp3:okhttp:3.0.0-RC1'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.0-RC1'
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'

这在 GitHub issue page that's closed 上有很好的记录,因此不容易找到。

那些抱怨 java.lang.AbstractMethodError: abstract method "void okhttp3.Callback.onFailure(okhttp3.Call, java.io.IOException)" 的人说,如果你不使用日志记录拦截器,你可以完全删除 okhttp3 的导入。

使用LoganSquare的用户还需要:

apt 'com.bluelinelabs:logansquare-compiler:1.3.4'
compile 'com.bluelinelabs:logansquare:1.3.4'
compile 'com.github.aurae.retrofit2:converter-logansquare:1.2.