Proguard的停止Javascript语言的WebView从工作 [英] Proguard stops Javascript in WebView from working
问题描述
我有一个类JSBridge(一个内部类),这是一个JavaScript接口:
私有类JsBridge实现JsCallback { / **
*为必填@param handlerName方法
* @参数jsonData数据通过从JavaScript传递
* @参数jsCallback的回调触发时handlername指定的处理程序已完成,可为空
* /
@JavascriptInterface
公共无效callHandler(最后弦乐handlerName,最后弦乐jsonData,最后弦乐jsCallback){
Log.d(App.TAG,从JS桥呼叫,接收+ handlerName);
} @JavascriptInterface
公共无效的onPageLoad(最后弦乐页面名){
Log.d(App.TAG,从JS桥呼叫,接收的onPageLoad - 我们的网页名称+页面名);
}
,直到我做一个发布版本使用ProGuard这工作得很好。我试过以下一些其他的SO答案,并添加了以下行我ProGuard的文件,但它并没有帮助。其结果是调试版本,我得到的回调,释放的版本我没有得到任何回调。
-keep公共类*实现com.mixcloud.player.view.JsCallback-keepclassmembers类*实现com.mixcloud.player.view.JsCallback {
<方法&GT ;;
}
-keep公共类*实现com.mixcloud.player.view.JsCallback-keepattributes *注释*
-keepattributes JavascriptInterface
-keep公共类com.mixcloud.player.view.JSRefreshWebView
-keep公共类com.mixcloud.player.view.JSRefreshWebView $ JsBridge
-keep公共类*实现com.mixcloud.player.view.JSRefreshWebView $ JsBridge
-keepclassmembers类*实现com.mixcloud.player.view.JSRefreshWebView $ {JsBridge
<方法&GT ;;
}
如果你的Javascript接口方法与@JavascriptInterface注解,你可以preserve他们
-keepclassmembers类* {
@ android.webkit.JavascriptInterface<方法&GT ;;
}
I have a class JSBridge (an inner class) which is a javascript interface:
private class JsBridge implements JsCallback {
/**
* @param handlerName method required
* @param jsonData data passed through from javascript
* @param jsCallback A callback to trigger when handler specified by handlername has finished, could be null
*/
@JavascriptInterface
public void callHandler(final String handlerName, final String jsonData, final String jsCallback) {
Log.d(App.TAG, "Bridge call from JS, received " + handlerName);
}
@JavascriptInterface
public void onPageLoad(final String pageName) {
Log.d(App.TAG, "Bridge call from JS, received onPageLoad - we have the page name " + pageName);
}
This works fine until I do a release build with proguard. I've tried following some other SO answers and have added the following lines to my proguard file, but it has not helped. The result is the debug version I get the callbacks, the release version I get no callbacks.
-keep public class * implements com.mixcloud.player.view.JsCallback
-keepclassmembers class * implements com.mixcloud.player.view.JsCallback {
<methods>;
}
-keep public class * implements com.mixcloud.player.view.JsCallback
-keepattributes *Annotation*
-keepattributes JavascriptInterface
-keep public class com.mixcloud.player.view.JSRefreshWebView
-keep public class com.mixcloud.player.view.JSRefreshWebView$JsBridge
-keep public class * implements com.mixcloud.player.view.JSRefreshWebView$JsBridge
-keepclassmembers class * implements com.mixcloud.player.view.JSRefreshWebView$JsBridge {
<methods>;
}
If your Javascript interface methods are annotated with @JavascriptInterface, you can preserve them with
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
这篇关于Proguard的停止Javascript语言的WebView从工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!