Android的Proguard的Javascript的接口故障 [英] Android Proguard Javascript Interface Fail

查看:140
本文介绍了Android的Proguard的Javascript的接口故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用了一块code如下描述

I use in my project a piece of code as described here

<一个href="http://lexandera.com/2009/01/extracting-html-from-a-webview/">http://lexandera.com/2009/01/extracting-html-from-a-webview/

我创建的.apk文件,我的设备上安装它,它正常工作。如果我尝试使用MyJavaScriptInterface的混淆使用ProGuard项目失败,该方法showHTML(字符串HTML)没有达到。

I create the .apk file, install it on my device and it correctly works. If I try to use the obfuscation with proguard the project fails, the method showHTML(String html) of MyJavaScriptInterface is not reached.

关于我的ProGuard配置了

My proguard configuration regarding that

-keep public class com.mypackage.MyClass.MyJavaScriptInterface
-keep public class * implements com.mypackage.MyClass.MyJavaScriptInterface
-keepclassmembers class * implements com.mypackage.MyClass.MyJavaScriptInterface { 
    <methods>; 
}

根据这个这个答案<一个href="http://stackoverflow.com/questions/5356560/android-proguard-javascript-interface-problem">Android ProGuard的Javascript的接口问题。

任何建议?提前致谢。 丹尼斯。

Any suggestion? Thanks in advance. Denis.

解决的。

由于埃里克的建议,我改变了Proguard的配置文件是这样的:

As Eric suggested, I changed the Proguard configuration file like this:

-keep public class com.mypackage.MyClass$MyJavaScriptInterface
-keep public class * implements com.mypackage.MyClass$MyJavaScriptInterface
-keepclassmembers class com.mypackage.MyClass$MyJavaScriptInterface { 
    <methods>; 
}

现在我的计划完美的作品。 谢谢你。

Now my project works perfectly. Thanks.

有关API 17+,你还需要preserve的@JavascriptInterface注释:

For API 17+ you also need to preserve the @JavascriptInterface annotations:

-keepattributes JavascriptInterface

<一个href="http://developer.android.com/reference/android/webkit/JavascriptInterface.html">http://developer.android.com/reference/android/webkit/JavascriptInterface.html

推荐答案

如果MyJavaScriptInterface是一个内部类的MyClass,ProGuard的期望一个完全合格的名称 com.mypackage.MyClass $ MyJavaScriptInterface 。与 $ 的命名约定用于ProGuard的运行所需的编译的类文件。需要注意的是ProGuard的提到的类名,它不能找到在输入罐的结构中,这表明这些名称可能已被拼错。

If MyJavaScriptInterface is an inner class of MyClass, ProGuard expects a fully qualified name com.mypackage.MyClass$MyJavaScriptInterface. The naming convention with $ is used in the compiled class files on which ProGuard operates. Note that ProGuard mentions class names in the configuration that it can't find in the input jar, suggesting that these names may have been misspelled.

这篇关于Android的Proguard的Javascript的接口故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆