When you call JS in the Android WebView, you confuse considerations __c#

Source: Internet
Author: User

Today there is a bug, is WebView and JS Interactive method How also can not adjust, debug package No problem, release package on the wrong, think is packing confused problem, played a not confused bag, sure enough, is confusing problem.

And then find the solution, and in the Proguard-project file there's 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-
class name to th E JavaScript Interface
# class:
#-keepclassmembers class Fqcn.of.javascript.interface.for.webview {
# Public   *;
#}</span>
Remove the annotation and replace the Fqcn.of.javascript.interface.for.webview with the class name you defined (the package name must also have, if the definition is an inner class, 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, it is 4.2 above version call JS interface in the method to use the declaration @javascriptinterface, and then confusion may lose the statement caused, Program can not call JS, you need to continue to add conditions in the configuration file,

-keepattributes *annotation*
-keepattributes *javascriptinterface*


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

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

-keepattributes *annotation*
-keepattributes *javascriptinterface*


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.