1. 混淆导致Webview没有执行JS回调
<!-- 这代码在webview内容里 -->
<javascript>
function fun(){
if(typeof umevent != 'undefined' && typeof umevent.clicked == 'function'){
umevent.clicked();
}
}
</javascript>
package com.a;
public class A{
public void funA(){
mWebview.addJavascriptInterface(this, "aaaa");
}
@JavascriptInterface
public void clicked(){
...;
}
}
应该在progurad-rules.pro文件里写
-keepclassmembers class com.a.A {
public void clicked();
}
2. webview格式化html
private String getHtmlData(String bodyHTML) {
String head = "<head>" +
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"> " +
"<style>img{max-width: 100%; width:auto; height:auto;}</style>" +
"</head>";
return "<html>" + head + "<body>" + bodyHTML + "</body></html>";
}