[TIMOB-15781] Android: KitKat crash when calling WebView method on wrong thread
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-11-23T01:18:52.000+0000 |
Affected Version/s | n/a |
Fix Version/s | 2013 Sprint 24, 2013 Sprint 24 Core, Release 3.2.0 |
Components | Android |
Labels | 4.4, android, crash, kitkat, merge-3.1.4, module_webview, qe-closed-3.2.0, qe-testadded, triage, webview |
Reporter | Mark Mokryn |
Assignee | Allen Yeung |
Created | 2013-11-20T20:44:15.000+0000 |
Updated | 2014-03-03T18:30:13.000+0000 |
Description
The following code crashes on Android 4.4, does not crash on Android 4.1.2.
The crash log is:
11-20 22:32:31.861: E/TiExceptionHandler(9656): (main) [0,995] - Message: Uncaught Error: java.lang.Throwable: A WebView method was called on thread 'KrollRuntimeThread'. All WebView methods must be called on the same thread. (Expected Looper Looper{41e338c0} called on Looper{41e52348}, FYI main Looper is Looper{41e338c0})
11-20 22:32:31.861: E/TiExceptionHandler(9656): (main) [0,995] - Source: Ti.API.debug("user agent: " + $.webview.userAgent);
index.xml:
<Alloy>
<Window class="container" fullscreen=true>
<WebView id="webview" url="/test.html" />
</Window>
</Alloy>
index.js:
Ti.API.debug('user agent: ' + $.webview.userAgent); // CRASH HERE ON KitKat
$.index.open();
lib/test.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Hi there</h2>
</body>
</html>
Prior to KitKat we're used to seeing this warning: 11-21 16:06:29.515: W/webview_proxy(4299): java.lang.Throwable: Warning: A WebView method was called on thread 'KrollRuntimeThread'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads. Looks like in KitKat they finally made good on their warning. :-(
Verified this for a non alloy & an alloy app & was able to reproduce the issue. Removing the "useragent" property in Ti.API.debug does not throw the error. Environment: Appcel Studio : 3.2.0.201311200357 Ti SDK : 3.2.0.v20131119142443 Mac OSX : 10.8.5 Alloy : 1.3.0 CLI - 3.2.0-alpha
On a general note: In KitKat Google changed the WebView to Chrome, so there may be more issues: https://developers.google.com/chrome/mobile/docs/webview/overview
I was able to reproduce this issue today on a nexus 4 running android 4.3 Environment: Appcel Studio : 3.2.0.201311211712 Ti SDK : 3.2.0.v20131119142443 Mac OSX : 10.8.5 Alloy : 1.3.0 CLI - 3.2.0-alpha
Test case:
1. Set your target SDK to API 18 or 19 by putting this in your tiapp.xml:
2. Run the test case 3. click the button 4. verify that no warning/errors appear relating to webview method called from wrong thread.
PR: https://github.com/appcelerator/titanium_mobile/pull/5016
Verified fixed on: Mac OSX 10.9 Mavericks Titanium Studio, build: 3.2.0.201311221859 Titanium SDK, build: 3.2.0.v20131125103938 CLI: 3.2.0-alpha Alloy: 1.3.0-alpha6 Android Device: Nexus 5, 4.4 (KitKat) Ran test case provided for Alloy and Classic projects. The test.html page is located and displayed correctly on screen. No error is thrown in console log. Closing.
This should be backported to 3.1.X . This bug will crash a lot of apps as KitKat adoption ramps up.
Yes, it is already scheduled for that. [~ayeung], can we prepare a backport for 3.1.X?