10

I tried to follow this tutorial: http://docs.phonegap.com/en/2.7.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android

and get the following error:

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

Here a guy explains the error: 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.

He tells the fix is easy, but does not explain how to fix it -.- Brilliant!

Obviously one fix is not to run it with an Android 2.2 emulator because it works with Android 4.2.

But how do I get it working in Android 2.2?

I want to build an application that is compatible from API Level 8 and up.

steros
  • 1,794
  • 2
  • 26
  • 60

1 Answers1

4

This is because Android 2.2 does not have the updated webkit with WebResource Response.

Try downloading the cordova 2.2 jar from here and putting it in you /libs folder at the base of your project. If there is none, create one. You might also have to add IceCreamCordovaWebViewClient.java to your sources (or if you choose to download the source code of cordova and add it as a dependency, you can add it to that source)

Or you can try using a regular WebViewClient/ChromeClient and doing the work yourself, as MH outlines in this post, copied below.

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.


EDIT:

Also, you can also try adding WebResourceResponse and dependencies to your src folder. Try downloading them from here

Community
  • 1
  • 1
dberm22
  • 3,187
  • 1
  • 31
  • 46
  • I also have the same error with a 2.3 AVD. I'm wondering if this error is causing a bug I'd like to fix. However, I'm a newbie with ADT (I mostly code HTML/CSS/JS...). Do you mean that I should copy both cordova-2.7.0.jar and 2.2.jar to the libs folder? and IceCreamCordovaWebViewClient.java to which folder? My project is targeting 4.2.2 but is it possible to target several versions at once? – Yako May 27 '13 at 10:03
  • Oh, if you already have 2.7, do not also copy 2.2. I think the easiest thing for you would be to use the 2.7 jar and add the IceCreamCordovaWebViewClient.java to your src folder, if the jar does not already have it (which 2.7 might). I don't know your application, but I would recommend using ShouldOverrideUrlLoading() if you want 2.x support. You could always check the api version of the phone and then do one or the other depending on the version. – dberm22 May 27 '13 at 14:21
  • You can also try adding WebResourceResponse and dependencies to your src folder. https://github.com/android/platform_frameworks_base/blob/master/core/java/android/webkit/WebResourceResponse.java – dberm22 May 27 '13 at 14:38
  • I have same issue some one can help me :http://stackoverflow.com/questions/24839836/salesforce-android-app-remote-access-application-authorization – Ramesh Somalagari Jul 19 '14 at 13:07