0
votes

I get the following error when running a retrofit application:

E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher Process: fr.univ_lehavre.greah.naoderapp, PID: 20894 java.lang.NoSuchMethodError: No virtual method log(Ljava/lang/String;)V in class Lokhttp3/internal/Platform; or its super classes (declaration of 'okhttp3.internal.Platform' appears in /data/app/fr.univ_lehavre.greah.naoderapp-2/split_lib_dependencies_apk.apk) at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:108) at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:157) at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:190) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163) at okhttp3.RealCall.access$100(RealCall.java:30) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127) at 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) at java.lang.Thread.run(Thread.java:761)

This is the class where I create the retrofit object :

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;
}

}

I am not sure which versions should I use.

These are the ones I'm currently using :

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'

Thank you.

1

1 Answers

4
votes

Try adding these versions.

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