我应该使用哪些版本的okhttp和okhttp logging-interceptor与Retrofit 2.1.0来避免这个错误?

时间:2018-05-24 09:13:35

标签: android rest retrofit okhttp

运行改装应用程序时出现以下错误:

  

E / AndroidRuntime:致命异常:OkHttp Dispatcher                     处理:fr.univ_lehavre.greah.naoderapp,PID:20894                     java.lang.NoSuchMethodError:类Lokhttp3 / internal / Platform中没有虚方法日志(Ljava / lang / String;)V;或者它的超级类(声明' okhttp3.internal.Platform'出现在/data/app/fr.univ_lehavre.greah.naoderapp-2/split_lib_dependencies_apk.apk)                         在okhttp3.logging.HttpLoggingInterceptor $ Logger $ 1.log(HttpLoggingInterceptor.java:108)                         在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)                         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)                         at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:607)                         在java.lang.Thread.run(Thread.java:761)

这是我创建改装对象的类:

public class RetrofitImpl {

private static Retrofit retrofit = null;
public static final String BASE_URL = "http://192.168.43.144:8080/";
//    public static final String BASE_URL = "http://10.0.2.2:8080/";

public static Retrofit getClient() {

    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

    retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .client(client)
            .build();
    return retrofit;
}

}

我不确定应该使用哪个版本。

这些是我目前正在使用的:

implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.0.0-RC1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.0.0-RC1'

谢谢。

1 个答案:

答案 0 :(得分:2)

尝试添加这些版本。

 compile 'com.squareup.okhttp3:logging-interceptor:3.9.1'
 compile 'com.squareup.retrofit2:retrofit:2.3.0'