Android的ProGuard的Javascript的接口问题 [英] Android proguard Javascript Interface problem

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

问题描述

混淆使用ProGuard之后,我的项目失败,javascriptinterface

My project after obfuscation with proguard fail with javascriptinterface

下面是一些建议,ProGuard的配置的链接,但它在我的情况下,不到风度工作

Here is the link with some suggestions for proguard configuration but it dosn't work in my case

<一个href="http://groups.google.com/group/android-developers/browse_thread/thread/f889e846fbf7ec3f?pli=1">http://groups.google.com/group/android-developers/browse_thread/thread/f889e846fbf7ec3f?pli=1

所以从Javascript调用松散结合相关的Java方法

So the calls from Javascript loose binding to the associated Java methods

关于我的ProGuard配置了

My proguard configuration regarding that

-keep public class com.trans_code.android.JavascriptCallback 
-keep public class * implements com.trans_code.android.JavascriptCallback 
-keepclassmembers class * implements com.trans_code.android.JavascriptCallback { 
    <methods>; 
} 
-keepclassmembers class * implements JavascriptCallback { 
    void on*(***);
} 
-keep public class com.trans_code.** {
  public protected *;
}

-keepclasseswithmembernames class com.MyActivity$JavascriptInterface

-keepclasseswithmembernames class com.MyActivity$JavascriptInterface {
    public protected *;
}

如果有人知道如何配置ProGuard的把它过滤掉相关的方法和类,这将帮助我很多

if anyone knows how to configure proguard to have it filter out related methods and classes that will help me a lot

推荐答案

从原来的线程类名是特定于用户的Java类,而不是一般的向所有的JavaScript接口。您实现的JavaScript接口只是一个简单的基类。

The class names from that original thread are specific to that users Java classes, and not generic to to all javascript interfaces. The javascript interface you implement is just a simple base class.

您需要更改它们以符合你的接口类的名称。

You need to change them to match the name of your interface class.

例如正确的配置的基础上,例如,从原来的线程,用于样品code WebViewDemo将是:

For example the correct configuration, based on the example from the original thread, for the sample code WebViewDemo would be:

-keep public class com.google.android.webviewdemo.WebViewDemo.DemoJavaScriptInterface
-keep public class * implements com.google.android.webviewdemo.WebViewDemo.DemoJavaScriptInterface 
-keepclassmembers class * implements com.google.android.webviewdemo.WebViewDemo.DemoJavaScriptInterface { 
    <methods>; 
} 

由于方法绑定工作,所有真正需要做的是保持将从JavaScript脚本调用从具有的名称混淆,但保持距离模糊不伤类名内的方法。

Due to the way the bindings work all that really needs to be done is to keep the inner methods that will be called from javascript from having the names obfuscated, but keeping the class name from obfuscation doesn't hurt.

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

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