Proguard JavascriptInterface <print> </print>

时间:2015-03-21 10:06:36

标签: android printing webview

我有使用proguard导出apk的问题。 Proguard说:proguard.ParseException:在&#39;;&#39;之前期待类成员名称。 对于这一行:print;

我在课堂上需要这个:

public class JIFace {
    @JavascriptInterface
    public void print(String data) {

当我从Progurad移除它时,接口不能被呼叫。

Progurad:

-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

-keepattributes JavascriptInterface

-keepattributes *Annotation*

-keepattributes JavascriptInterface
-keep public class com.imh.sos.WebCPU_Mail$JIFace
-keep public class * implements com.imh.sos.WebCPU_Mail$JIFace
-keepclassmembers class com.imh.sos.WebCPU_Mail$JIFace { 
    <methods>; 
}


-keepattributes JavascriptInterface
-keep public class com.imh.sos.WebCPU_Mail$print
-keep public class * implements com.imh.sos.WebCPU_Mail$print
-keepclassmembers class  com.imh.sos.WebCPU_Mail$print { 
    <methods>; 
}




-keepattributes JavascriptInterface
-keep public class com.imh.sos.WebCPU_Mail$JIFace
-keep public class * implements com.imh.sos.WebCPU_Mail$JIFace
-keepclassmembers class com.imh.sos.WebCPU_Mail$JIFace { 
    <print>; 
}

-keepattributes JavascriptInterface
-keep public class com.imh.sos.WebCPU_Mail$print
-keep public class * implements com.imh.sos.WebCPU_Mail$print
-keepclassmembers class com.imh.sos.WebCPU_Mail$print { 
    <print>; 
}

SDK是19。

谢谢

2 个答案:

答案 0 :(得分:0)

这对我有用:

-keep public class package_name.activity_name$MyJavaScriptInterface

-keep public class * implements package_name.activity_name$MyJavaScriptInterface
-keepclassmembers class package_name.activity_name$MyJavaScriptInterface {
<methods>;}

-keepattributes JavascriptInterface

答案 1 :(得分:0)

我尝试了2天不同的进入但没有结果。

在onPageFinished之后我想加载:

String ht = "javascript:window.droid.print(document.getElementsByTagName('TBODY')[0].innerHTML);";
webView.loadUrl(ht);

然后我想要@JavascriptInterface调用:

public class JIFace {
        @JavascriptInterface
        public void print(String data) {

                data ="<html>" + "<meta http-equiv=" + "content-type" + "content=" + "text/html; charset=UTF-8" + ">" + data + "</html>";
                 System.out.println(data);

当我在app中以调试模式运行或没有proguard作为已签名的应用程序时,everythink就可以了。 我需要一些提示!

PS:经过2年的发展,我想发表我的作品,现在最后一件事不起作用。我讨厌Proguard,但我需要! :(