首页 文章

OkHttpClient在更新Retrofit到Retrofit 2后损坏

提问于
浏览
6

从改造到改造2更新后出现此错误 .

致命异常:OkHttp Dispatcher进程:nz.co.datacom.mars.junction,PID:21616 java.lang.NoSuchMethodError:没有虚拟方法日志(Ljava / lang / String;)类Lokhttp3 / internal / Platform中的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上的okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163) .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)at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:588)at java.lang.Thread.run(Thread.java:818)

我在应用程序中使用的libs版本是:

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之间的几个不同的版本,但没有一个工作 .

有任何想法吗?提前致谢 .

1 回答

  • 12

    和你有同样的问题 .

    首先,扔出去:

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

    改造有 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'
    

    希望能解决问题 .

相关问题