android – Retrofit logging interceptor exception-ThrowExceptions

Exception or error:

I am trying to enable Logging with Retrofit but I am getting this exception:

07-13 12:44:53.278 28698-29248/com.xxxx.debug E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
                                                                                         Process: com.xxxx.debug, PID: 28698
                                                                                         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/data/com.xxxx.debug/files/instant-run/dex/slice-realm-optional-api_16b022358933b490d810e358ea76b13cd4d88163-classes.dex)
                                                                                             at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(
                                                                                             at okhttp3.logging.HttpLoggingInterceptor.intercept(
                                                                                             at okhttp3.RealCall$ApplicationInterceptorChain.proceed(
                                                                                             at com.xxxx.api.RetrofitClient$1.intercept(
                                                                                             at okhttp3.RealCall$ApplicationInterceptorChain.proceed(
                                                                                             at okhttp3.RealCall.getResponseWithInterceptorChain(
                                                                                             at okhttp3.RealCall.access$100(
                                                                                             at okhttp3.RealCall$AsyncCall.execute(
                                                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(
                                                                                             at java.util.concurrent.ThreadPoolExecutor$

And this is how I am doing it:

public class RetrofitClient {

    private static MyService instance;

    public static MyService getInstance(Context context) {
        if (instance == null) {
            instance = newInstance(context);
        return instance;

    private static MyService newInstance(Context context) {
        Retrofit retrofit = new Retrofit.Builder()

        return retrofit.create(MyService.class);

    private static OkHttpClient getClient() {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor()

        OkHttpClient.Builder httpClient = new OkHttpClient.Builder()
                .addInterceptor(new Interceptor() {
                    public Response intercept(Chain chain) throws IOException {
                        Request original = chain.request();

                        Request request = original.newBuilder()
                                .header("api-key", "...")
                                .header("version-app", "-")
                                .header("platform", "android")
                                .header("version", "-")
                                .header("device", "-")
                                .method(original.method(), original.body())

                        Response response = chain.proceed(request);// <-- CRASH

                        return response;


I have tried adding only one interceptor but still crashing. I am using this dependencies:

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'

What am I doing wrong here?

EDIT: Well this is embarrassing… the problem solved itself. I changed nothing, I am revising all my commits and both RetrofitClient and build.gradle haven’t changed. The problem, therefore, was not related to gradle dependencies or versions.

Luckily someone will cast some light on this exception!

How to solve:

Retrofit 2.1.0 relies on OkHttp 3.3.0, so I would use the same version for the Logging Interceptor (which is part of OkHttp):

compile 'com.squareup.okhttp3:logging-interceptor:3.3.0'


Can you try to add the below dependency

 compile 'com.squareup.okhttp3:okhttp:3.4.1'

And let me know if there is any progress

You can also refer this link.


In my case this pair of dependencies solved the problem:

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'

Anyway, the problem is in dependency consistency…


Facing the same issue, if you facing this issue sometime not randomly then try to restart android studio with Invalidate/Restart. Maybe its fixed in future updates.

1. Uninstall previous build.
2. File-> Invalidate/Cache -> Invalidate and

Leave a Reply

Your email address will not be published. Required fields are marked *