I have an application which uses ksoap with an underlying okhttp
connection.
The majority of the time it works - however during a connection retry the application crashes with a NoSuchMethodError. Stack trace below
Fatal Exception: java.lang.NoSuchMethodError: okhttp3.internal.http.HttpEngine.recover
at okhttp3.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:493)
at okhttp3.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
at okhttp3.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:261)
at org.ksoap2.transport.OkHttpServiceConnectionSE.openOutputStream(OkHttpServiceConnectionSE.java:124)
at org.ksoap2.transport.HttpTransportSE.sendData(HttpTransportSE.java:292)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:184)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
at uk.org.xibo.xmds.CheckConnection.run(CheckConnection.java:106)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
I do use proguard, and have added rules so that okhttp is left alone:
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
My grade file contains these dependencies:
compile 'com.squareup.okio:okio:1.8.0'
compile 'com.squareup.okhttp3:okhttp:3.3.0'
compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.1'
I have tried decompiling the resulting APK and can confirm that the okhttp3.internal.http.HttpEngine.recover
method does exist.
The source for the missing method is here: https://github.com/square/okhttp/blob/master/okhttp-urlconnection/src/main/java/okhttp3/internal/huc/HttpURLConnectionImpl.java#L495
I am not sure how to proceed debugging this issue OR whether I have done something obviously wrong.
Thanks for any assistance.
EDIT:
New theory - ksoap2-android has a reference to part of the okhttp library:
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-urlconnection</artifactId>
<version>3.2.0</version>
</dependency>
The HttpEngine
method is contained in the main okhttp library - could it be that my reference to okhttp v3.3.0 is providing the HttpEngine
which is being used by HttpURLConnectionImpl
v3.2.0 from the ksoap2 library?
I've downgraded my okhttp dependency to compile 'com.squareup.okhttp3:okhttp:3.2.0'
and have installed on a few devices to test. If this is the problem I will update with the answer.
Apologies for the delay - reverting to compile 'com.squareup.okhttp3:okhttp:3.2.0'
in my gradle file did solve the problem.