【问题标题】:OkHttpClient broken after updated Retrofit to Retrofit 2更新改造到改造 2 后,OkHttpClient 损坏
【发布时间】:2016-11-30 22:46:46
【问题描述】:

从改造升级到改造2后,我得到了这个错误。

致命异常:OkHttp 调度程序 进程:nz.co.datacom.mars.junction,PID:21616
java.lang.NoSuchMethodError:没有虚拟方法 Lokhttp3/internal/Platform 类中的 log(Ljava/lang/String;)V;或其 超类('okhttp3.internal.Platform'的声明出现在 /data/app/nz.co.datacom.mars.junction-1/base.apk)
在 okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:109) 在 okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:157) 在 okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:190) 在 okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163) 在 okhttp3.RealCall.access$100(RealCall.java:30)
在 okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
在 okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 在 java.lang.Thread.run(Thread.java:818)

我在应用中使用的库版本是:

    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0'
    compile 'com.squareup:otto:1.3.7'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'

不确定是不是因为 okhttp 版本,但我尝试了 2.3.0 和 3.4.0 之间的几个不同版本,但都没有工作。

有什么想法吗?提前致谢。

【问题讨论】:

    标签: java android retrofit retrofit2 okhttp3


    【解决方案1】:

    和你有同样的问题。

    首先,扔掉:

    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    

    Retrofit 具有 okhttp3 作为依赖项,因此不需要它。而且,当你检查here时,Retrofit 2.1.0依赖于okhttp 3.3.0,所以可能会有冲突。请记住,最终的依赖版本是您在gradle 文件中编写的版本。如果你不写它,那么Gradle 会自动解析它并获取正确的版本。

    还有更新版本的 Logging Interceptor 和 urlconnection:

    compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    compile 'com.squareup.okhttp3:okhttp-urlconnection:3.4.1'
    

    希望能解决问题。

    【讨论】:

      【解决方案2】:

      此外,了解修复最重要的是确保 okhttp3 依赖项具有与协作者声明的 here 相同的版本号

      【讨论】:

        猜你喜欢
        • 2018-02-04
        • 1970-01-01
        • 2020-09-25
        • 1970-01-01
        • 2021-02-13
        • 1970-01-01
        • 2019-07-25
        • 1970-01-01
        • 2016-12-12
        相关资源
        最近更新 更多