2013-07-23 32 views
7

停止使用Javascript在網頁視圖我有一個類JSBridge(一個內部類),這是一個JavaScript接口:Proguard的無法工作

private class JsBridge implements JsCallback { 

    /** 
    * @param handlerName method required 
    * @param jsonData data passed through from javascript 
    * @param jsCallback A callback to trigger when handler specified by handlername has finished, could be null 
    */ 
    @JavascriptInterface 
    public void callHandler(final String handlerName, final String jsonData, final String jsCallback) { 
     Log.d(App.TAG, "Bridge call from JS, received " + handlerName); 
    } 

    @JavascriptInterface 
    public void onPageLoad(final String pageName) { 
     Log.d(App.TAG, "Bridge call from JS, received onPageLoad - we have the page name " + pageName); 
    } 

,直到我做一個發佈版本使用ProGuard這工作得很好。我試過下面的一些其他的答案,並添加了以下幾行到我的proguard文件,但它沒有幫助。結果是我得到回調的調試版本,發佈版本我沒有回調。

-keep public class * implements com.mixcloud.player.view.JsCallback 

-keepclassmembers class * implements com.mixcloud.player.view.JsCallback { 
    <methods>; 
} 
-keep public class * implements com.mixcloud.player.view.JsCallback 

-keepattributes *Annotation* 
-keepattributes JavascriptInterface 
-keep public class com.mixcloud.player.view.JSRefreshWebView 
-keep public class com.mixcloud.player.view.JSRefreshWebView$JsBridge 
-keep public class * implements com.mixcloud.player.view.JSRefreshWebView$JsBridge 
-keepclassmembers class * implements com.mixcloud.player.view.JSRefreshWebView$JsBridge { 
    <methods>; 
} 

回答

17

如果您的JavaScript接口方法與@JavascriptInterface註釋,你可以用

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

保留它們稀釋是我認爲我的文檔中看到了這一點,在一片混亂中,我想我應該將該包與我的實際JavaScript接口類放在一起。這工作第一次! – serenskye

+0

我有一個奇怪的情況,我導出我的應用程序使用上述配置,它在Android 2.3.7,但不是在Nexus 5(Android 4.2) – StarWars