【发布时间】:2025-12-09 18:45:02
【问题描述】:
运行改造应用程序时出现以下错误:
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) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 在 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'
谢谢。
【问题讨论】:
标签: android rest retrofit okhttp