0

A webview has bridge and methods that are called by web and annotated with @JavascriptInterface.

The app works fine in the debug build and release build without Proguard. But when the Proguard is turned on, the application does not receive callbacks from the web.

Javascript methods that are called by web are annotated with the @Keep annotation and the webview bridge class too. But for some reason, the webview bridge methods in the android apps still don't get called.

Edit: This is the code for the method to run by web.

     /**
     * This method gets called from the WebApp and logs the user
     * in the app using native Facebook Sign In implementation
     * in {@link MainActivity#initFacebookSignIn(String callback)}
     */
    @JavascriptInterface
    public void initFacebookSignIn(String callback) {
        activity.initFacebookSignIn(callback);
    }

Any ideas?

Dhruvam Sharma
  • 1,661
  • 14
  • 22

1 Answers1

1

Add these rules to your proguard:

-dontwarn javax.annotation.**
-keepattributes Signature
-keepattributes Exceptions
-keepattributes SetJavaScriptEnabled
-keepattributes JavascriptInterface
-keepattributes InlinedApi
-keepattributes SourceFile,LineNumberTable
-keepattributes *Annotation*

-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}
Masoud Mokhtari
  • 2,390
  • 1
  • 17
  • 45