android进行代码混淆时,webview用js进行交互失效了;
界面WebviewFagment在com.hello.adapter包下
js交互的类在WebviewFagment文件中定义
混淆规则
-keepattributes *Annotation*
-keepattributes *JavascriptInterface*
-dontwarn com.hello.adapter.**
-keep class com.hello.adapter.**{*;}
哪里有问题吗?
解决了,查了很多资料,关于@JavascriptInterface被优化掉的解决办法都只提到了:
-keepattributes Annotation
-keepattributes JavascriptInterface
还要添加一句即可:
-keep class android.webkit.JavascriptInterface {*;}