Oui*_*sal 1 rest android retrofit okhttp
运行改造应用程序时出现以下错误:
E/AndroidRuntime:致命异常:OkHttp 调度程序进程: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_dependency_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;
}
Run Code Online (Sandbox Code Playgroud)
}
我不确定应该使用哪个版本。
这些是我目前正在使用的:
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'
Run Code Online (Sandbox Code Playgroud)
谢谢。
尝试添加这些版本。
compile 'com.squareup.okhttp3:logging-interceptor:3.9.1'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2506 次 |
最近记录: |