Android volley proguard throws java.lang.RuntimeException: Stub

烈酒焚心 提交于 2019-12-24 07:27:57

问题


I'm using Android Volley network library which when kept in debugging + release modes works perfectly fine, until I added Twilio client SDK. Now it works fine when in debugging mode but when in release mode throws this error

 E/Volley: [105358] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Stub!
                                   java.lang.RuntimeException: Stub!
                                       at org.apache.a.h.<init>(SourceFile:6)
                                       at com.android.volley.toolbox.HurlStack.performRequest(SourceFile:109)
                                       at com.android.volley.toolbox.BasicNetwork.performRequest(SourceFile:97)
                                       at com.android.volley.NetworkDispatcher.run(SourceFile:114)

The log taken from the error interface of the Android volley string reqiest

01-10 16:42:27.330 522-522/? D/LOGINACTIVITY: java.lang.RuntimeException: Stub!-java.lang.RuntimeException: Stub!-java.lang.RuntimeException: Stub!

Have looked for the same and got some response where they are asking to keep the JUint in top of the dependency list. Still the error persists. Any sort of help will be appreciated. TIA

Update 1:

Codebase added

StringRequest strReq = new StringRequest(Request.Method.POST,
                    AppConfig.URL_LOGIN, new Response.Listener<String>() {

                @Override
                public void onResponse(String response) {

                    ....

                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d("LOGINACTIVITY", error.getLocalizedMessage() + "-" + error.getMessage() + "-" + error.getCause());

                }
            }) {

                @Override
                protected Map<String, String> getParams() {
                    // Posting parameters to login url
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("email", email);
                    params.put("password", password);
                    return params;
                }

            };

            // Adding request to request queue
            strReq.setShouldCache(false);
            strReq.setRetryPolicy(new DefaultRetryPolicy(AppConfig.DEFAULT_RETRY_TIME, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
            AppController.getInstance().addToRequestQueue(strReq, tag_string_req);

Update 2:

Use-case added

  1. App starts and requests user to allow the permissions like location, sms read, ..
  2. Once the user agrees to those set of permissions, the user is allowed to enter the email-id & password.
  3. Email-id & password are the parameters passed via the getParam().
  4. When the following is requested through volley StringRequest it ends up going to "OnErrorResponse", where the error message is "java.lang.RuntimeException: Stub!"

Update 3:

Proguard rules added

 # Twilio Client
 -keep class com.twilio.** { *; }
 # Apache HttpClient
-dontwarn org.apache.http.**
-keepattributes InnerClasses
-keep public class android.net.http.SslError
-keep public class android.webkit.WebViewClient

-dontwarn android.webkit.WebView
-dontwarn android.net.http.SslError
-dontwarn android.webkit.WebViewClient

-keepattributes EnclosingMethod

回答1:


I'm posting my solution in case if someone finds it useful someday.

The cause of "stub!"

This happens when using Proguard and the com.apache.http.legacy library in Android SDK 23.

As a matter of fact, all the methods are stubbed out to throw an exception with the message “Stub!” when you call them. How cute.

The real android.jar implementations live on the emulator, or your real Android device.

So changing the proguard rules solved the following, seems like twilio is using old http library or something not sure.

So, here's my current solution

   # Twilio Client
 -keep class com.twilio.** { *; }

-keep class org.webrtc.** { *; }
-keep class com.twilio.video.** { *; }
-keepattributes InnerClasses

-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.** { *; }
-keep class com.android.internal.http.multipart.** { *; }
-dontwarn org.apache.http.**
-dontwarn android.webkit.**

-keepattributes EnclosingMethod

Source Link to SO answer



来源:https://stackoverflow.com/questions/41567579/android-volley-proguard-throws-java-lang-runtimeexception-stub

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!