3

我在我的项目中导入了 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 解析器,我需要导入特定版本的 Retrofit (2.0.0-beta3),否则我会考虑使用以前版本的 Retrofit。如何解决这个问题?

4

1 回答 1

2

问题是改造需要某些版本的 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 问题页面上有详细记录,因此不容易找到。

那些抱怨的人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.
于 2016-02-04T15:27:22.950 回答