
Crosswalk Project is a replacement for Android WebView. Project development
This review note continues a short series of two articles on an interesting project called Crosswalk. In it, I will talk about what has changed in the Crosswalk project from version 14.43.343.17 and whether it has become more convenient to use it now.
Let me remind you that the Crosswalk Project is a runtime built on open source technologies for HTML applications. The basis for the Crosswalk Project is Google Chromium. Crosswalk Project is also an open source project and is distributed under the BSD License . In general, if you still support early versions of Android, then this is a good replacement for the system Android WebView.
You can find previous articles at the following links:
- Crosswalk Project is a replacement for Android WebView. Project Integration
- Crosswalk Project is a replacement for Android WebView. Integration issues
Changes to Crosswalk.
From version 14 to version 20, a lot of changes and improvements were made to the project, it makes no sense to list everything. You yourself can familiarize yourself with them in release notes .
I will list only a few that are most interested in me:
- Rebase to Chromium 50
- Support external extensions for Crosswalk Webview on Android
- Add ability to intercept touch events on the XWalkView
- When onReceivedLoadError occurs, a Toast notification is displayed to the user instead of a dialog (as the user cannot do anything to respond to the error)
- New helper class XWalkInitializer to initialize XWalkView asynchronously
- Size optimizations (Enable ProGuard for Crosswalk to compress APK size, LZMA support etc.)
Also, a large number of corrections were made to the project, the most critical ones are listed there.
Additional details.
In previous articles, I described a number of problems and their solutions for previous versions of Crosswalk. I am glad that many of them were solved in the project itself and now "dancing with a tambourine" is not needed.
The XWalkCookieManager and XWalkSettings classes have been moved to packages that are more suitable for them :
org.xwalk.core.internal.XWalkCookieManager; → org.xwalk.core.XWalkCookieManager
org.xwalk.core.internal.XWalkSettings → org.xwalk.core.XWalkSettings
XWalkSettings is available directly through the method in the XWalkView object. Also, XWalkView itself can return its User-Agent to us. Now for all this there is no need to resort to the use of reflection.
Added a new call to Crosswalk (in the XWalkResourceClient class) for processing resource requests :
public XWalkWebResourceResponse shouldInterceptLoadRequest(XWalkView view, XWalkWebResourceRequest request)
An analogue of a very convenient and accessible call with Android API 21 in the standard WebView:
public WebResourceResponse shouldInterceptRequest (WebView view, WebResourceRequest request)
Now you can easily find out with what method the request was made: GET or POST.
Also, a special method has been added to XWalkView for obtaining content images :
public void captureBitmapAsync(XWalkGetBitmapCallback callback)
The onBackPressed () method began to be correctly called and the opportunity appeared to use the setOnTouchListener (OnTouchListener l) method. So now there is no need to intercept button clicks and touch events in dispatch methods.
You can find documentation on the latest and all previous versions of the API here .
Some problems in new versions.
Currently, the latest available version in the repository is 20.50.533.12, but unlike the penultimate version 19.49.514.5, it already has a minSdkVersion value equal to API 16. Crosswalk 19 still supports all versions of Android starting with API 14.
Despite the fact that even for Crosswalk 16 it was stated: "Android support libraries (eg support-v4, support-v7 etc) are no longer bundled by Crosswalk ...". From version 16 to the last 20, the import for the support-v4 library is incorrectly registered, therefore, if you use a specific version of this library in your project and do not want the project to automatically build with the latest version, you must exclude it when adding Crosswalk to your project :
compile('org.xwalk:xwalk_core_library:19.49.514.5') {
// avoid pulling incorrect version of support library
exclude group: 'com.android.support', module: 'support-v4'
}
Crosswalk Lite, reduce the size of the assembly.
In previous articles, I did not mention a significant enough problem - increasing the size of the assembly when adding Crosswalk. Crosswalk itself is going for two architectures: x86 and armv7. Accordingly, the libraries for each of them have a size of ~ 20Mb, i.e. if you build a universal build, then overhead will be about 40Mb.
There are 2 ways to improve the situation with the extra size: build separate apk for each architecture or use the lightweight version of Crosswalk - Crosswalk Lite. Crosswalk Lite is an attempt to solve the problem by abandoning some of the library's features .
Here are more accurate data on Lite size and the regular version of Crosswalk: Crosswalk Lite 10-15Mb vs. Crosswalk 20Mb.
However, in addition to a limited set of features, Crosswalk Lite has a number of minuses:
- Activity must inherit from XWalkActivity;
- Application must inherit from XWalkApplication;
- initialization must be carried out asynchronously in a special method, and at the first start the library itself is unpacked and the user sees a message about it.
Unfortunately, the latest version of Crosswalk Lite 17.46.460.1 currently available refused to start with an error (like its 2 predecessors):
W/XWalkInternalResources: org.xwalk.core.R$styleable.ButtonCompat is not int.
E/SysUtils: ApplicationContext is null in ApplicationStatus
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 22829 (osswalkembedded)
Therefore, the only real method to reduce the size is to build separate builds for each architecture.
Examples are added to the updated test project available on GitHub .
Conclusions.
The latest versions take into account many, including the ones I mentioned, shortcomings of previous releases. And, if you are already using Crosswalk, then you definitely should upgrade to new versions.
However, another question remains. Can Crosswalk now serve as a good replacement for system WebView? If you support older versions of Android (including Android 4 versions of Jelly Bean and KitKat), then obviously Crosswalk may come in handy. If you plan to support only Android 5+, then the answer is not obvious.
With the 5th version of Android, an update of the system WebView from Google Play became available (and new, convenient API requests appeared), and with the 7th version of Android, the Google Chrome application is designed to replace the standard system component. It is difficult to say how necessary an additional library is in this case. Perhaps for some projects, a complete identity of behavior on all versions of the OS will outweigh the increase in size and the need to update another library.