2017-01-18 22 views
0

我露出@JavascriptInterface回調調試通過Android Studio中的應用程序時,它工作得很好網頁視圖,但是如果通過APK安裝了該應用JavaScript的回調失敗:的Android的WebView的JavaScript回調無法在APK沒有Proguard的

「遺漏的類型錯誤:NativeApp.onProgress是不是一個函數」

我知道,不正確的Proguard的規則,可能會導致這個問題,但是在這種情況下,項目未使用ProGuard與調試出現問題,發佈APKS。

如果我檢查APK,方法是存在的。

public class MyServiceWithEmbeddedWebView {  
    ... 

    public createWebview() { 
    ... 
    webView.addJavascriptInterface(this, "NativeApp"); 
    ... 
    } 

    @JavascriptInterface 
    void onProgress(int loaded, int total) { 
     ... 
    } 

    ... 
} 

任何想法?

回答

0

@JavascriptInterface方法的範圍更改爲public解決了該問題。

所以此工程的APK安裝:

@JavascriptInterface 
public void onProgress(int loaded, int total) { 
    // this is public 
} 

這並沒有爲APK安裝工作,但是當被Android Studio調試器部署的工作就像一個冠軍:

@JavascriptInterface 
void onProgress(int loaded, int total) { 
    // this is NOT public 
} 

如何討厭!

相關問題