Android Proguard JavaScript Interface Fail

Android Proguard Javascript Interface Fail

If MyJavaScriptInterface is an inner class of MyClass, ProGuard expects a fully qualified name com.mypackage.MyClass$MyJavaScriptInterface. The naming convention with $ is used in the compiled class files on which ProGuard operates. Note that ProGuard mentions class names in the configuration that it can't find in the input jar, suggesting that these names may have been misspelled.

Proguard mess Javascript Interface functions when targeting SDK in Android Manifest above 17

I copy my answer from this topic for you: https://stackoverflow.com/a/19994873/1735499

And, if you are using Proguard, remember to add this

-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}

-keepattributes JavascriptInterface
-keep public class com.mypackage.MyClass$MyJavaScriptInterface
-keep public class * implements com.mypackage.MyClass$MyJavaScriptInterface
-keepclassmembers class com.mypackage.MyClass$MyJavaScriptInterface {
<methods>;
}

If it's still not OK, add this

-keepattributes *Annotation*

Note: your MyJavaScriptInterface must be Public class

Ref#: Android Proguard Javascript Interface Fail

Br,

Frank

JavascriptInterface not working with proguard on Android 4.2

I have found the solution, I just have to tell proguard to keep the JavascriptInterface annotation. I added this to my proguard configuration to make it work:

-keepattributes JavascriptInterface

Android Javascript Interface Fail

The problem is that proguard obfuscates the FinishExtract method.
Then the javascript can't find it because it assumes the name is still "FinishExtract"

To fix it you can change your code to:

public class JavaScriptInterface  implements cmn.Proguard.KeepMembers {

Your proguard config specifies that classes which implement KeepMembers should stay unobfuscated.

Javascript interface not working with android 4.2

And, if you are using Proguard, remember to add this

-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}

-keepattributes JavascriptInterface
-keep public class com.mypackage.MyClass$MyJavaScriptInterface
-keep public class * implements com.mypackage.MyClass$MyJavaScriptInterface
-keepclassmembers class com.mypackage.MyClass$MyJavaScriptInterface {
<methods>;
}

If it's still not OK, add this

-keepattributes *Annotation*

Note: your MyJavaScriptInterface must be Public class

Ref#: Android Proguard Javascript Interface Fail



Related Topics



Leave a reply



Submit