2013-05-08 59 views
10

运行HelloCordova当我试图按照本教程: http://docs.phonegap.com/en/2.7.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android找不到类“android.webkit.WebResourceResponse”在Android 2.2

,并出现以下错误:

05-08 15:35:59.845: E/dalvikvm(307): Could not find class 'android.webkit.WebResourceResponse', referenced from method org.apache.cordova.CordovaWebViewClient.getWhitelistResponse 

这里一个人解释错误:https://issues.apache.org/jira/browse/CB-3041

This is a known issue. Because Android 2.3 does not have android.webkit.WebResourceResponse, this code is considered dead by Android 2.3's Dalvik. This means your whitelisting doesn't work properly like it does on Android 4.x, as per CB-2099. I'm going to keep this open, but lower the priority, since we know what causes it and it's an easy "First Bug" for someone if they really want to fix this. 

他告诉修复是容易的,但并没有解释如何解决它-.- 辉煌!

很显然,一个修复程序不是用Android 2.2模拟器运行它,因为它可以与Android 4.2一起使用。

但是,如何让它在Android 2.2中工作?

我想构建一个从API级别8以上兼容的应用程序。

回答

4

这是因为Android 2.2没有WebResource Response的更新的webkit。

尝试从here下载cordova 2.2 jar并将其放入项目底部的you/libs文件夹中。如果没有,请创建一个。您可能还需要添加IceCreamCordovaWebViewClient.java到你的源代码(如果你选择下载科尔多瓦的源代码,并将其添加为一个依赖,你可以把它添加到源)

或者你可以尝试使用常规WebViewClient/ChromeClient和自己完成工作,如MHthis post中概述,复制如下。

If you want to do something similar for Android 2.x, you might want to try using the earlier mentioned shouldOverrideUrlLoading(WebView view, String url) to avoid loading the page, fetch it manually, replace the reference to the css file with your own, and finally call loadData(String data, String mimeType, String encoding) (or loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl)) on the WebView, passing in the manipulated html content as a string.


编辑:

此外,你也可以尝试加入WebResourceResponse和依赖关系到你的src文件夹中。尝试从here下载他们

+0

我也有一个2.3 AVD同样的错误。我想知道这个错误是否导致我想修复的错误。不过,我是一个ADT的新手(我主要编码HTML/CSS/JS ...)。 你的意思是我应该将cordova-2.7.0.jar和2.2.jar都复制到libs文件夹中?和IceCreamCordovaWebViewClient.java文件夹?我的项目的目标是4.2.2,但可以同时定位多个版本吗? – Yako 2013-05-27 10:03:13

+0

哦,如果你已经有2.7,不要也复制2.2。我认为最简单的事情是使用2.7 jar,并将IceCreamCordovaWebViewClient.java添加到你的src文件夹中,如果jar没有它(2.7可能)。我不知道你的应用程序,但如果你想要2.x支持,我会推荐使用ShouldOverrideUrlLoading()。您可以随时检查手机的api版本,然后根据版本进行一种或另一种操作。 – dberm22 2013-05-27 14:21:17

+0

您也可以尝试将WebResourceResponse和依赖关系添加到src文件夹中。 https://github.com/android/platform_frameworks_base/blob/master/core/java/android/webkit/WebResourceResponse.java – dberm22 2013-05-27 14:38:27