Precautions for obfuscation when calling js in android webview
Today, there is a bug, that is, the way webview interacts with js cannot be tuned. If the debug package is faulty, the release package may fail. Think about the obfuscation during packaging, A non-obfuscation package is a obfuscation problem.
Then find the solution, which is included in the proguard-project file.
# 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 *;#}Uncomment and fqcn. of. javascript. interface. for. change webview to the class name you define (the package name must also be available. If you define an internal class, it is cn. wj. ui. webViewActivity $ myInterface). There is no problem in the 4.1 system, but it still does not work on the 4.2 host. Look for it again, it turns out that when calling the js interface in version 4.2 or later, you need to use the Declaration @ JavascriptInterface in the method. This declaration may be lost when obfuscation occurs, and the program cannot call js. You need to continue adding conditions in the configuration file,
-Keepattributes * Annotation *
-Keepattributes * JavascriptInterface *
Therefore, when webview and js interaction are used, these configurations should be added to the confusion file:
-Keepclassmembers class cn. xx. xx. Activity $ AppAndroid {public *;}-keepattributes * Annotation *-keepattributes * JavascriptInterface *