android混淆后webview显示问题

来源:互联网 发布:懒人做饭知乎 编辑:程序博客网 时间:2024/06/15 16:13


在混淆过程中,项目中设计webview与js交互的部分,出现webview显示异常或者不显示的问题。这其中问题可能是两者之间交互在混淆之后无法正常进行。因此在混淆申明的时候要对这些进行申明,需要添加:

-keepattributes *Annotation* 
-keepattributes *JavascriptInterface*

若仍无法正常显示,可尝试具体到含有webview的class不混淆,在proguard-project.txt中有这样一段话:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;

#}

fqcn.of.javascript.interface.for.webview改为工程中指定的包名下指定类,在混淆文件加上这些申明:

-keepclassmembers class com.xxx.xxx.xxx(包名.类名) {
  public *;
}

-keepattributes *Annotation*
-keepattributes *JavascriptInterface*

有更好的想法欢迎探讨。


0 0
原创粉丝点击