如何配置ProGuard的对JavaScript界面? [英] How to configure proguard for javascript interface?
问题描述
我有一个实现了一个web视图这需要使用JavascriptInterface的。它的正常工作时,不进行模糊处理,但一旦Proguard的是积极的,这是行不通的。我在这里看了看其他的答案,但我仍然无法得到它的工作。
I have a implemented a Webview which takes use of JavascriptInterface. It's working fine when not obfuscating, but at once Proguard is active, it does not work. I've looked here at other answers, but i still can't get it working.
部分的WebView类的:
public class Activity_Webview {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new JavaScriptInterface (), "HTMLOUT");
webView.setWebViewClient(mWebViewClient);
}
public class JavaScriptInterface implements NonObfuscateable{
@JavascriptInterface
public void processHTML(String html) {
handleFinishFromWebView(html);
}
}
我已经试过在Proguard的
-keep public class * implements com.project.NonObfuscateable
-keepclassmembers class * implements NonObfuscateable {
public void processHTML(java.lang.String);
}
我也试过这个(当不执行NonObfuscateable接口
-keep public class com.project.Activity_Webview.JavaScriptInterface
-keep public class * implements com.project.Activity_Webview.JavaScriptInterface
-keepclassmembers class * implements com.project.Activity_Webview.JavaScriptInterface {
<fields>;
<methods>;
}
没有任何人有什么可能是错误的想法? 在此先感谢
Does anybody have an idea of what could be wrong? Thanks in advance
推荐答案
无论你的配置可以工作,如果他们不包含错别字:
Both your configurations could have worked if they hadn't contained typos:
-
ProGuard的要求完全合格的名称:
ProGuard requires fully qualified names:
NonObfuscateable
- > com.project.NonObfuscateable
编译的类使用$作为分隔符的内部类:
Compiled classes use '$' as a separator for inner classes:
com.project.Activity_Webview.JavaScriptInterface
- > com.project.Activity_Webview $ JavaScriptInterface
在控制台日志,ProGuard的打印出对这种可疑的错别字说明。
In the console log, ProGuard prints out notes about such suspected typos.
保持注释Javascript的接口方法的一个更普遍的解决方案:
A more general solution for keeping annotated Javascript interface methods:
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
这篇关于如何配置ProGuard的对JavaScript界面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!