Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoSuchMethodError: No virtual method log(Ljava/lang/String;)V in class Lokhttp3/internal/Platform; #2839

Closed
ouyangzn opened this issue Sep 6, 2016 · 18 comments

Comments

@ouyangzn
Copy link

ouyangzn commented Sep 6, 2016

it's fine if I delete

HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BASIC); builder.interceptors().add(logging);

but if i use okhttp3 logging-interceptor, throw this exception:

java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread. at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:62) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:154) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:833) Caused by: 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/com.ouyangzn.topgithub-2/base.apk) at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:109) 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.execute(RealCall.java:57) at retrofit2.OkHttpCall.execute(OkHttpCall.java:174) at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:171) at rx.internal.operators.OperatorSubscribeOn$1$1$1$1.call(OperatorSubscribeOn.java:85) at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:222) at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)  at java.util.concurrent.FutureTask.run(FutureTask.java:237)  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:154)  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)  at java.lang.Thread.run(Thread.java:833) 

@swankjesse
Copy link
Collaborator

You need to use the same version for all of your OK dependencies. If you don’t, things won't work!

@ouyangzn
Copy link
Author

ouyangzn commented Sep 7, 2016

I used the same version:
compile "com.squareup.okhttp3:okhttp:${OKHTTP_VERSION}"
compile "com.squareup.okhttp3:logging-interceptor:${OKHTTP_VERSION}"
OKHTTP_VERSION = 3.2.0

Now i kown, the problem is caused by retrofit, i used :
compile "com.squareup.retrofit2:retrofit:${RETROFIT_VERSION}"
RETROFIT_VERSION = 2.1.0

retrofit 2.1.0 used okhttp3.3.0, so ...
I convert retrofit version to 2.0.2, it's ok.

@JakeWharton
Copy link
Collaborator

Do not downgrade Retrofit. Upgrade OkHttp.

On Wed, Sep 7, 2016, 1:52 AM ouyangzn notifications@github.com wrote:

I used the same version:
compile "com.squareup.okhttp3:okhttp:${OKHTTP_VERSION}"
compile "com.squareup.okhttp3:logging-interceptor:${OKHTTP_VERSION}"
OKHTTP_VERSION = 3.2.0

Now i kown, the problem is caused by retrofit, i used :
compile "com.squareup.retrofit2:retrofit:${RETROFIT_VERSION}"
RETROFIT_VERSION = 2.1.0

retrofit 2.1.0 used okhttp3.3.0, so ...

I convert retrofit version to 2.0.2, it's ok.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#2839 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEEET1RrHgJuRQa9Lk_Fy5tuLHPXdYyks5qnlE1gaJpZM4J1luG
.

@ouyangzn
Copy link
Author

ouyangzn commented Sep 8, 2016

ok , i know, thanks, i was ignore that okhttp's latest version is 3.4.1;

@mclark4386
Copy link

Is there any where to look up which versions work together... I'm getting this with the latest versions of both...

@JakeWharton
Copy link
Collaborator

JakeWharton commented Nov 30, 2016 via email

@mclark4386
Copy link

I meant what versions of OkHttp that work with what versions of retrofit

@JakeWharton
Copy link
Collaborator

JakeWharton commented Nov 30, 2016 via email

@mclark4386
Copy link

mclark4386 commented Nov 30, 2016

    def RETROFIT_VERSION = "2.1.0"
    compile "com.squareup.retrofit2:retrofit:${RETROFIT_VERSION}"
    compile "com.squareup.retrofit2:converter-gson:${RETROFIT_VERSION}"
    compile "com.squareup.retrofit2:converter-scalars:${RETROFIT_VERSION}"
    compile ("com.squareup.retrofit2:converter-simplexml:${RETROFIT_VERSION}"){
        exclude group: 'xpp3', module: 'xpp3'
        exclude group: 'stax', module: 'stax-api'
        exclude group: 'stax', module: 'stax'
    }

    def OKHTTP_VERSION = "3.4.2"
    compile "com.squareup.okhttp3:okhttp:${OKHTTP_VERSION}"
    compile "com.squareup.okhttp3:logging-interceptor:${OKHTTP_VERSION}"

but still getting 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/<package>-2/base.apk)

When I try to use the logging interceptor:


        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

        api = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(client)
                .addConverterFactory(SimpleXmlConverterFactory.create())
                .build().create(FeedApi.class);

@mclark4386
Copy link

changed code to

 HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

        try {
            Response resp = client.newCall(new Request.Builder().url(BASE_URL+"/b2w").build()).execute();
            Log.d("MAIN","got resp:"+resp.body().toString());
        } catch (IOException e) {
            e.printStackTrace();
        }

and still getting the same error.

@JakeWharton
Copy link
Collaborator

JakeWharton commented Dec 2, 2016 via email

@mclark4386
Copy link

I believe this is what you meant:
screen shot 2016-12-02 at 12 07 43 am

and this was the results:
screen shot 2016-12-02 at 12 02 37 am

@artem-zinnatullin
Copy link
Contributor

artem-zinnatullin commented Dec 2, 2016 via email

@mclark4386
Copy link

mclark4386 commented Dec 2, 2016

Yeah, it was blank the first run as well...^^;
screen shot 2016-12-02 at 11 22 51 am
Command line got me something.... looking through it...

@mclark4386
Copy link

mclark4386 commented Dec 2, 2016

Here is what I'm hoping is the important info from the command line output:


compile - Classpath for compiling the main sources.
+--- io.realm:realm-android-library:2.2.0
|    +--- io.realm:realm-annotations:2.2.0
|    \--- com.getkeepsafe.relinker:relinker:1.2.2
+--- io.realm:realm-annotations:2.2.0
+--- com.android.support:appcompat-v7:25.0.1
|    +--- com.android.support:support-v4:25.0.1
|    |    +--- com.android.support:support-compat:25.0.1
|    |    |    \--- com.android.support:support-annotations:25.0.1
|    |    +--- com.android.support:support-media-compat:25.0.1
|    |    |    \--- com.android.support:support-compat:25.0.1 (*)
|    |    +--- com.android.support:support-core-utils:25.0.1
|    |    |    \--- com.android.support:support-compat:25.0.1 (*)
|    |    +--- com.android.support:support-core-ui:25.0.1
|    |    |    \--- com.android.support:support-compat:25.0.1 (*)
|    |    \--- com.android.support:support-fragment:25.0.1
|    |         +--- com.android.support:support-compat:25.0.1 (*)
|    |         +--- com.android.support:support-media-compat:25.0.1 (*)
|    |         +--- com.android.support:support-core-ui:25.0.1 (*)
|    |         \--- com.android.support:support-core-utils:25.0.1 (*)
|    +--- com.android.support:support-vector-drawable:25.0.1
|    |    \--- com.android.support:support-compat:25.0.1 (*)
|    \--- com.android.support:animated-vector-drawable:25.0.1
|         \--- com.android.support:support-vector-drawable:25.0.1 (*)
+--- com.android.support:recyclerview-v7:25.0.1
|    +--- com.android.support:support-annotations:25.0.1
|    +--- com.android.support:support-compat:25.0.1 (*)
|    \--- com.android.support:support-core-ui:25.0.1 (*)
+--- com.android.support:cardview-v7:25.0.1
|    \--- com.android.support:support-annotations:25.0.1
+--- com.android.support.constraint:constraint-layout:1.0.0-beta4
|    \--- com.android.support.constraint:constraint-layout-solver:1.0.0-beta4
+--- com.squareup.retrofit2:retrofit:2.1.0
|    \--- com.squareup.okhttp3:okhttp:3.3.0 -> 3.4.2
|         \--- com.squareup.okio:okio:1.9.0
+--- com.squareup.retrofit2:converter-gson:2.1.0
|    +--- com.squareup.retrofit2:retrofit:2.1.0 (*)
|    \--- com.google.code.gson:gson:2.7
+--- com.squareup.retrofit2:converter-scalars:2.1.0
|    \--- com.squareup.retrofit2:retrofit:2.1.0 (*)
+--- com.squareup.retrofit2:converter-simplexml:2.1.0
|    +--- com.squareup.retrofit2:retrofit:2.1.0 (*)
|    \--- org.simpleframework:simple-xml:2.7.1
+--- com.squareup.okhttp3:okhttp:3.4.2 (*)
\--- com.squareup.okhttp3:logging-interceptor:3.4.2
     \--- com.squareup.okhttp3:okhttp:3.4.2 (*)

Any ideas? Btw thanks @artem-zinnatullin for pointing the command line out^^

@happysingh23828
Copy link

This solution facebook/react-native#27250 (comment) worked for me.

@Ku-Dou
Copy link

Ku-Dou commented Feb 9, 2022

I have the same problem,but i dont know how to solve it

@dumbfingers
Copy link

@Ku-Dou

Cause of this problem is:

  • mismatch of the okhttp versions inside retrofit and logging interceptor

In order for the logging interceptor to work you will need to use exactly same version numbers in okhttp & logging interceptor.

If you are using Retrofit, you can find the okhttp version inside retrofit from here:
https://github.com/square/retrofit/blob/master/gradle/libs.versions.toml#L17

and use the same version for logging interceptor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants