When JS is called in Android WebView, it is confusing to note

Source: Internet
Author: User

Today there is a bug, that is, WebView and JS interaction method can not be adjusted, Debug package problem, release package on the error, think is the problem of packaging confusion, hit a not confused package, sure enough, is the problem of confusion.

And then just find the solution, in the Proguard-project file there is a sentence

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:14PX;" ># If your project uses WebView with JS, uncomment the following# and specify the fully qualified class name to the Jav Ascript interface# Class:#-keepclassmembers class Fqcn.of.javascript.interface.for.webview {# public   *;#}</ Span>
lift the note and put Fqcn.of.javascript.interface.for.webview The class name you define yourself (the package name must also have, if the inner class is defined, it is cn.wj.ui.webviewactivity$ MyInterface), in 4.1 of the system is no problem, but 4.2 of the machine or not, and then look for, oh, the original is more than 4.2 version of the call JS interface needs in the method to use the declaration @ Javascriptinterface, and then confusion may be lost when the declaration is caused, the program cannot invoke JS, need to continue to add conditions in the configuration file,

-keepattributes *annotation*
-keepattributes *javascriptinterface*


So when using WebView and JS interactions, these configurations should be added to the obfuscation file:

-keepclassmembers class Cn.xx.xx.activity$appandroid {public  *;} -keepattributes *annotation*-keepattributes *javascriptinterface*


When JS is called in Android WebView, it is confusing to note

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.