[TIMOB-13065] Android: API 16 breaks remote web services from local files
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-10-28T18:38:06.000+0000 |
Affected Version/s | n/a |
Fix Version/s | 2013 Sprint 22, 2013 Sprint 22 API, Release 3.2.0 |
Components | Android |
Labels | android, jellybean, module_android, qe-testadded, triage, webView |
Reporter | Mark Mokryn |
Assignee | Ping Wang |
Created | 2013-03-14T00:07:03.000+0000 |
Updated | 2015-07-28T14:06:34.000+0000 |
Edited original - I previously referenced the wrong Android flag. The link above is now correct, the flag is setAllowUniversalAccessFromFileURLs. Thanks
This seems to be a problem only on device; Emulator looks to work even if 4.1.x
@Davide - I did not try on emulator, but I did spend a few hours debugging why all of a sudden I'm getting null origin errors from my AJAX calls.... For now, my workaround is to set targetSdkVersion="14", but clearly this flag must be a new option in WebView configuration.
submitted PR: https://github.com/appcelerator/titanium_mobile/pull/4438
The pull request (just 3 lines of code!) has been working for me in production for quite some time now, battle tested on Android versions from 10 through 18, please commit it to enable web APIs from local webview files on Jellybean.
[~mokesmokes], I left some comments on your PR in github. Can you update your PR and provide a test case? Thanks.
OK, I'll do it over the weekend.
Here is a test case that demonstrates the problem and fix. Note I tested this on 3.1.x, not 3.2.0 since I couldn't get the 3.2.0 CLI to work, and I can't mess too much with my production environment - so please check. Without the fix, this test case will work on iOS and Android devices < API 16, and will fail API >= 16. With the fix it works on all. I will submit a new PR for 3.2.0. 1. Make sure to build for Jelly Bean, e.g. in tiapp.xml:
2. Here is an example in Alloy: index.xml:
index.js:
app/lib/test.html:
New PR: https://github.com/appcelerator/titanium_mobile/pull/4850
This needs to be reopened. On SDK 3.2.3 this problem is causing apps to crash running on Android 2.3.3 (API Level 10) when setAllowUniversalAccessFromFileURLs is invoked by webView Apps run fine on 3.2.0 and 3.2.2. Workaround is to build with 3.2.2. [INFO] : dalvikvm: Could not find method android.webkit.WebSettings.setAllowUniversalAccessFromFileURLs, referenced from method ti.modules.titanium.ui.widget.webview.TiUIWebView.
Can you please post an example app? This code in the SDK has not changed since 3.2.0
Just ran the latest Kitchen Sink downloaded from the Dashboard and it crashes with the following stack trace using an Android 2.3.3 emulator (Google API Level 10) and SDK 3.2.3 when you go into Base UI => Views => Web Views => Local URL. Then I tried it using SDK 3.2.2 and it still crashed with the same stack trace. Then I changed Target SDK to 16 with SDK 3.2.2 and it still crashed with the same stack trace. Then I changed to SDK 3.2.0 and it still crashed... Using Ti Studio build: 3.3.0.201407100905, Android SDK Tools 22.6.3, SDK Platform-tools 19.02, and SDK Build-tools 17 to 19.1. Our previous tests were done with an HTC Desire running Android 2.3.5 on a different Mac development system. Yes, we've also noted that the code hasn't changed although this testing indicates that the fix doesn't work for any of the 3.2.x SDKs on API Level 10. Please note that Google Maps are also currently broken on API Level 10 platforms. So given that 15-25% of users are still on API Level 10 platforms, this is bad news for our customers and our reputation as quality app developers... [INFO] : dalvikvm: Could not find method android.webkit.WebSettings.setAllowUniversalAccessFromFileURLs, referenced from method ti.modules.titanium.ui.widget.webview.TiUIWebView.
OK, the app.js for the simplest test case is the following. This crashes on the Google API Level 10 emulator. win = Ti.UI.createWindow(); web = Ti.UI.createWebView({ url: 'local_webview.html' }); win.add(web); win.open(); local_webview.html is the same used in Kitchen Sink.
Are you using an unmodified version of the SDK? Here is the only call to that method in the codebase (TiUIWebView.java), and it's been this way since 3.2.0:
Yes, we are running stock 3.2.xGA versions of the SDKs. Try running Kitchen Sink with the Google Android API Level 10 emulator or a real 2.3.3+ phone. I am told that Genymotion cuts corners and doesn't provide an accurate API Level 10 emulator. We also looked at the SDK source code and we agree that it looks impossible, but we have published apps in the Android Play Store that are crashing because of the call to setAllowUniversalAccessFromFilesURLs when a webView is opened built with 3.2.3GA on an Android 2.3.5 phone.
htc Desire HD, Android 2.3.5 KitchenSink 3.3.0 built w/ Ti SDK 3.2.3.GA on MacOS 10.9.4, Android build-tools 20, Platform-tools 20 Base UI => Views => Web Views => Local URL ... [INFO] : dalvikvm: Could not find method android.webkit.WebSettings.setAllowUniversalAccessFromFileURLs, referenced from method ti.modules.titanium.ui.widget.webview.TiUIWebView.
Same here on all emulators < api level 16, on sdk 3.2.3 and 3.3.0. Even when explicitly build for api level 10. Can this issue be reopened?
Does the issue occur on devices for you?
I did not find this issue on my test devices but these were all Android 4+. I wanted to test on a 2.3 tablet but forgot to borrow it from my daughter :-). I'll look around for one. I can confirm this issue disappears when using sdk 3.2.2.
We can confirm that this problem goes away on 3.40RC2. We re-tested today with 3.2.3 on an HTC Inspire/Desire running 2.3.5 and it does fail when accessing locally stored HTML files.
Great! Is there an ETA for 3.40?
Please could you tell me in which version of titanium sdk this update is available ? thanks
Im using 3.5.1.GA and the problem seems to be not resolved. thanks