OkHttpClient在更新Retrofit到Retrofit 2后损坏

Lon*_*Dao 6 java android retrofit retrofit2 okhttp3

从改造到改造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)位于java.lang.Thread.run的java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:588)(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'
Run Code Online (Sandbox Code Playgroud)

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

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

R. *_*ski 12

和你有同样的问题.

首先,扔出去:

compile 'com.squareup.okhttp3:okhttp:3.2.0'
Run Code Online (Sandbox Code Playgroud)

改造具有okhttp3依赖性,因此不需要.而且,当你在这里 检查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'
Run Code Online (Sandbox Code Playgroud)

希望能解决问题.