运行改造应用程序时出现以下错误:
E / AndroidRuntime:致命异常:OkHttp分派器进程:fr.univ_lehavre.greah.naoderapp,PID:20894 java.lang.NoSuchMethodError:没有虚拟方法日志(Ljava /郎/字符串;)V类Lokhttp3 /内部/平台;或它的超类(的“okhttp3.internal.Platform”声明出现在/data/app/fr.univ_lehavre.greah.naoderapp-2/split_lib_dependencies_apk.apk)在okhttp3.logging.HttpLoggingInterceptor $记录仪$ 1.登录(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 . 访问$ 100以java.util.concurrent.ThreadPoolExecutor.runWorker(RealCall.java:30)在okhttp3.RealCall $ AsyncCall.execute(RealCall.java:127)在okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) (ThreadPoolExecutor.java:1133)java.lang.Thread.run上的java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:607)(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 回答
尝试添加这些版本 .