Compile QWebKit component for Android

As announced Qt team ported Qt libraries to work on mobile system also but with some limitations. The most "important" limitation (in my opinion) is the choice to not include QWebKit (or QtWebEngine) component into mobile system library set. As replacement of this lack Qt team provide the QtWebView component that is a wrapper around the system native web browser engine.

The declared cause if this choice is the strong rules of Apple store avoiding the use of any different web browser engine except the system native available. Starting from this point Qt team decided to not include the browser engine in the distribution for mobile systems. Unfortunately the solution proposed with QtWebView have huge limitations and can be used only for a very simple application. It miss a large number of features usually exported by the standard Qt browser engine. It's true that this still is a "young" component and surely new features will be added in the next versions of Qt libraries but a lot of limits will remain cause the "wrapper" nature of the component itself. For IOS system there is no alternative since, in any case, the rules exclude any hack but for Android system, fortunately, it still exist the possibility to compile and include the QWebKit component (with some additional work as obvious). Please, keep in mind Qt team declared QWebKit component as deprecated and plan to remove it in some future version of Qt. This tutorial was verified using the Qt version 5.4.1 where QWebKit is still available but we don't guarantee it will work for future versions. Another important note is I didn't test all the QWebKit functionalities but only the basic browsing than I can not be sure if all the component features will work as expected.

Get Qt 5 sources

Before start explanation about compilation process a short note regarding how to get Qt sources for compile (that will be one step during compilation process). Basically there are two ways to get sources. The first, more easy, would be to directly download the .zip or tar.gz from the official Qt site here and extract all files in some place. The second way is to use the git tool for obtain sources directly from repository. The command for get it is the following:

git clone git://code.qt.io/qt/qt5.git [denstination folder]

However this will download the entire repository with the latest sources committed. In case you want to get and recompile only a specific Qt version (for example 5.4.1) you need to add some options in this format (please note, you need to use a recent version of git supporting these params):

git clone -b 5.4.1 --single-branch git://code.qt.io/qt/qt5.git qt5

This will prepare for download only 5.4.1 branch (in our example). Once command finished you need to enter inside the folder just created (in our example qt5) and type the command:

perl init-repository

This will download the entire sources of Qt 5.4.1 version (perl executable is provided with git package).

Compile on Linux

Official instructions to compile Qt 5 for Android platform in Linux came from here. Follow a resume of all points included additional info and differences:

1.  Download Android SDK from here (SDK Tools only) and extract in some place. Once extracted go to the <pat/to/sdk>/tools subfolder and run the android executable. This will open the SDK manager. Install API levels 10, 11, 16 and 18.

2.  Download Android NDK from here and install it in some place. Select the right version based to the Linux system you are going to compile in (32 or 64 bit system).

3.  Install Java JDK (version 1.6+, required 32 bit).

4.  Get Qt 5 sources (see above for instructions).

5.  In add of the standard packages python and perl that should be already installed in each standard Linux distribution you need to install the additional following packages: bison, flex, gperf.

6.  Set environment variables:

export JAVA_HOME="/path/to/jdk"
export PATH="$JAVA_HOME/bin:$PATH"
export ANDROID_SDK_ROOT="/path/to/android-sdk"

7.  Configure for compilation by typing this command line:

./configure -xplatform android-g++ -nomake tests -nomake examples -android-ndk [path/to/android-ndk] -android-sdk [path/to/android-sdk] -android-ndk-host [linux-x86 or linux-x86_64] -android-toolchain-version 4.9 -skip qttranslations -skip qtserialport -skip qtwebkit-examples -no-warnings-are-errors -skip qtwebengine -release

Please note, this command line will configure for generate release version as you can see from the final option. In case you need debug version also just change the last option to debug and restart from point 7. The option android-ndk-host refer to the Linux system you are using for compile, you need to set if the system is 32 or 64 bit based. Also note the component qtwebengine has been skipped by compilation since can not be compiled for Android.

8.  Start compilation by run:

make

9.  Once finished compilation process install with:

make install

By default the script will install the library package into /usr/local/Qt-xx.x.x path.

Compile on Windows

Compilation on Windows would be theoretically possible but highly discouraged since too much complex. Code, scripts and makefiles made to compile QWebKit component for Android are optimized to work on Linux and compile on Windows require to patch some part of these files and add a lot of common tools usually available in Linux (like, for example, cat, make, flex and so on). Since using both systems we are basically making a cross-compile operation doesn't have much importance the system used as base than my suggestion is to compile Qt on Linux using a virtual machine and then copy the additional webkit files on Windows Qt libraries folder. In details the files you need to copy from your just compiled library set to the default Windows Qt Android library folder (android_armv7) are the following:

lib\libQt5WebKit.la
lib\libQt5WebKit.prl
lib\libQt5WebKit.so
lib\libQt5WebKitWidgets.la
lib\libQt5WebKitWidgets.prl
lib\libQt5WebKitWidgets.so
lib\cmake\Qt5WebKit\*.*
lib\cmake\Qt5WebKitWidgets\*.*
lib\pkgconfig\Qt5WebKit.pc
lib\pkgconfig\Qt5WebKitWidgets.pc
include\QtWebKit\*.*
include\QtWebKitWidgets\*.*
mkspecs\modules\qt_lib_webkit.pri
mkspecs\modules\qt_lib_webkit_private.pri
mkspecs\modules\qt_lib_webkitwidgets.pri
mkspecs\modules\qt_lib_webkitwidgets_private.pri
plugins\webkit\*.*
imports\QtWebKit\*.*
qml\QtWebKit\*.*

Once added the files you can compile an Android app using QWebKit component. \^_^/

Comments

Popular posts from this blog

Access GPIO from Linux user space

Launch an app from Android shell terminal

Qt 5 and " Failed to load platform plugin 'windows' " error