alexrainman / ModernHttpClient

ModernHttpClient
MIT License
126 stars 28 forks source link

java.lang.NoSuchMethodError when proguard is turned on #12

Closed lassana closed 6 years ago

lassana commented 6 years ago

If proguard is enabled for the project, modernhttpclient crashes the app when a request fails (e.g. when Internet connection is not available). This happens with 2.7.0 and 2.7.1. I suppose it started happen with one of latest Xamarin updates.

[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Java.Lang.LinkageError: no non-static method "Lokhttp3/RealCall;.request()Lokhttp3/Request;"
[MonoDroid]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <0cb6f52bb7614e72b155f1cb952b81d4>:0 
[MonoDroid]   at Java.Interop.JniEnvironment+InstanceMethods.GetMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature) [0x0005b] in <1b64b7e1a0ed42abb18b4f9dd5c7cbae>:0 
[MonoDroid]   at Android.Runtime.JNIEnv.GetMethodID (System.IntPtr kls, System.String name, System.String signature) [0x00007] in <02ec485a3627426aa4be1cc56f805171>:0 
[MonoDroid]   at Square.OkHttp3.ICallInvoker.Request () [0x00012] in <4853fd89632f4f6395eb8abc24957e1e>:0 
[MonoDroid]   at ModernHttpClient.AwaitableOkHttp+OkTaskCallback.OnFailure (Square.OkHttp3.ICall p0, Java.IO.IOException p1) [0x00006] in <646665afcc914360a767aab8985f2a63>:0 
[MonoDroid]   at Square.OkHttp3.ICallbackInvoker.n_OnFailure_Lokhttp3_Call_Ljava_io_IOException_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_p0, System.IntPtr native_p1) [0x00017] in <4853fd89632f4f6395eb8abc24957e1e>:0 
[MonoDroid]   at (wrapper dynamic-method) System.Object.5219d6f1-e979-4a1d-bcb7-24854388d8eb(intptr,intptr,intptr,intptr)
[MonoDroid]   --- End of managed Java.Lang.LinkageError stack trace ---
[MonoDroid] java.lang.NoSuchMethodError: no non-static method "Lokhttp3/RealCall;.request()Lokhttp3/Request;"
[MonoDroid]     at md53445bfa005abb70b0a2fcd6c25bc64be.AwaitableOkHttp_OkTaskCallback.n_onFailure(Native Method)
[MonoDroid]     at md53445bfa005abb70b0a2fcd6c25bc64be.AwaitableOkHttp_OkTaskCallback.onFailure(AwaitableOkHttp_OkTaskCallback.java:31)
[MonoDroid]     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:148)
[MonoDroid]     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
[MonoDroid]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
[MonoDroid]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
[MonoDroid]     at java.lang.Thread.run(Thread.java:818)

My proguard configuration file contains these two lines required by OkHttp3:

-dontwarn okhttp3.**
-dontwarn okio.**

Any idea how to resolve it? Proguard is extremely important for us, so disabling it is not an option.

lassana commented 6 years ago

I'm able to fix the crash it by the obvious rule -keep class okhttp3.RealCall { *; }, but I'm not sure if this is enough.

alexrainman commented 6 years ago

I am not able to reproduce this.

alexrainman commented 6 years ago

I am going to include a catch for Java.Lang.LinkageError but also this line to force the linker to include RealCall class:

var call = Square.OkHttp3.RealCall.FromArray<int>(new[] { 0 });
lassana commented 6 years ago

Thanks for the info

alexrainman commented 6 years ago

It happens on release mode dont?

lassana commented 6 years ago

Yes, on release, although I haven't tried debug+proguard.

alexrainman commented 6 years ago

I will keep this open as i cannot reproduce it.

Petiephant commented 5 years ago

I've had this crash today as well on the latest version, v2.7.2. Seems to be fixed with the proguard rule above.