JavaScript Interface Not Working with Android 4.2

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

Android 4.2.1, WebView and javascript interface breaks

From the Android 4.2 documentation:

Caution: If you've set your targetSdkVersion to 17 or higher, you must add the @JavascriptInterface annotation to any method that you want available your web page code (the method must also be public). If you do not provide the annotation, then the method will not accessible by your web page when running on Android 4.2 or higher.

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

JavaScript Interface to a Browser not working in 4.2.2

If your android:targetSdkVersion is set to 17 or higher, you need to add the @JavascriptInterface annotation to getSomeData(), as is described in the documentation.

Javascript to native Android calls do not work on Android 4.2

You might try building for API 17, but setting the minimum version lower. Something like <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17"/>

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.



Related Topics



Leave a reply



Submit