我尝试按照本教程进行操作: http://docs.phonegap.com/en/2.7.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android
并得到以下错误:
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 及更高版本兼容的应用程序。
最佳答案
这是因为 Android 2.2 没有更新的带有 WebResource Response 的 webkit。
尝试从 here 下载 cordova 2.2 jar并将其放入项目底部的/libs 文件夹中。如果没有,请创建一个。您可能还必须添加 IceCreamCordovaWebViewClient.java添加到您的源代码(或者如果您选择下载 cordova 的源代码并将其添加为依赖项,您可以将其添加到该源代码)
或者您可以尝试使用常规的 WebViewClient/ChromeClient
并自己完成工作,如 MH this 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 callloadData(String data, String mimeType, String encoding)
(orloadDataWithBaseURL(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 下载它们
关于android - 在 Android 2.2 上运行 HelloCordova 时找不到类 'android.webkit.WebResourceResponse',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16444996/