Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make org.apache.http.legacy work with ProGuard (azure mobile services)?

The problem:

I'm using android mobile services, which relies on androidhttpclient.

Referencing org.apache.http.legacy resolves all the problems and the app runs just fine. However, with proguard on, I keep running into issues.

The problem plays out in two scenarios. If I keep the export checkbox checked (in jave build path), I get a 'Stub!' exception as expected (see discussion below)(see screenshot for which checkbox I'm talking about)

enter image description here

The runtime crash of type: "Stub!":

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.stuffd/com.stuffd.MainActivity}: java.lang.RuntimeException: Stub!
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2345)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
       at android.app.ActivityThread.access$800(ActivityThread.java:149)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:211)
       at android.app.ActivityThread.main(ActivityThread.java:5317)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.RuntimeException: Stub!
   at org.apache.http.message.AbstractHttpMessage.(AbstractHttpMessage.java:7)
   at org.apache.http.client.methods.HttpRequestBase.(HttpRequestBase.java:7)
   at org.apache.http.client.methods.HttpGet.(HttpGet.java:8)
   at com.microsoft.windowsazure.mobileservices.table.MobileServiceJsonTable.executeGetRecords(MobileServiceJsonTable.java:952)
   at com.microsoft.windowsazure.mobileservices.table.MobileServiceJsonTable.executeUrlQuery(MobileServiceJsonTable.java:183)
   at com.microsoft.windowsazure.mobileservices.table.MobileServiceJsonTable.execute(MobileServiceJsonTable.java:160)
   at com.microsoft.windowsazure.mobileservices.table.MobileServiceTable.execute(MobileServiceTable.java:158)
   at com.microsoft.windowsazure.mobileservices.table.MobileServiceTable.execute(MobileServiceTable.java:249)
   at com.microsoft.windowsazure.mobileservices.table.query.ExecutableQuery.execute(ExecutableQuery.java:101)

If however, I keep the checkbox unchecked (as suggested - see discussion below), I get and AbstractMethodError exception.

java.lang.RuntimeException: An error occured while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:300)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
       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:811)
Caused by: java.lang.AbstractMethodError: abstract method "java.lang.String org.apache.http.client.methods.HttpRequestBase.getMethod()"
       at android.net.http.AndroidHttpClient.getMethod(AndroidHttpClient.java:283)
       at android.net.http.AndroidHttpClient.execute(AndroidHttpClient.java:301)

proguard config used:

-dontwarn org.apache.http.**
-dontwarn android.net.http.**
-dontwarn com.microsoft.windowsazure.mobileservices.**

Has anyone else run into this and has figured it out?

like image 564
rothschild86 Avatar asked Aug 22 '15 19:08

rothschild86


1 Answers

Here's what I am using, allowing the OS to properly replace the stubbed methods at runtime.

-keep class org.apache.http.** { *; }
-keep class org.apache.commons.codec.** { *; }
-keep class org.apache.commons.logging.** { *; }
-keep class android.net.compatibility.** { *; }
-keep class android.net.http.** { *; }
-dontwarn org.apache.http.**
-dontwarn android.webkit.**

It's all the stubbed packages provided by org.apache.http.legacy.jar.

like image 188
TalkLittle Avatar answered Nov 06 '22 09:11

TalkLittle