Getting Started with Qt for Android
Requirements
In order to use Qt for Android, you need the following:
- The Android SDK Tools
- The Android NDK
- Apache Ant v1.8 or later
- Java SE Development Kit (JDK) v6 or later. You can also use OpenJDK on Linux.
- On Windows, you need the following additional installations:
- MinGW v4.8.0 revision 2
- Android Debug Bridge (ADB) driver on the Windows platform to enable USB debugging. The default USB driver on Windows does not allow debugging. For details about how to get the USB driver, see http://developer.android.com/sdk/win-usb.html.
After installing the driver, try running a few basic adb commands and check whether your device responds to it.
Note: You must set the JAVA_HOME environment variable to the JDK install directory path so that Qt Creator finds the binaries required to build your application.
After installing these tools, update the Android SDK to get the API and tools packages required for development. You can update the SDK using the android tool that comes with the SDK Tools package. For example, on Ubuntu the following command starts the Android SDK Manager, which enables you to select the packages you want to install:
./android update sdk
Installing Qt for Android
You can install the binary package for Qt 5.1 or later to get Qt for Android. The installer containing the open-source binary packages are available for download from the Qt project Downloads page.
Note: Enterprise packages are available from the Try Qt Enterprise page. Qt for Android is also available as part of Qt Mobile Edition, see qt.digia.com for details.
You can also choose to build the binaries from the Qt sources, that is, cross-compile Qt 5.x for Android on Linux (X11) , Windows, and Mac OS X platforms. If you chose to do so, follow these instructions:
- Install the required tools, SDK, and the compiler toolchains listed in the Requirements section.
Note: Ensure that your build environment fulfills the requirement for the platform (Linux, Mac OS X, and Windows) you have chosen.
- Set the following environment variables if your build platform is Windows:
- ANDROID_NDK_HOST=windows or windows-x86-64 depending on which NDK you are using.
- PATH=%JAVA_HOME%\bin;<MINGW_ROOT>\bin;%PATH%
- Download the Qt 5 sources either from the Downloads page or from the Git repository.
Note: If you are downloading the sources from the Git repository, you must initialize your Git clone using the perl init-repository command to pull the latest sources for all the Qt 5.x modules. Ensure that you have perl v5.14 or later installed.
- Run the following command to configure the Qt 5.x sources to cross-compile Qt for Android:
On Linux/X11 and Mac OS X:
./configure -developer-build -xplatform android-g++ -nomake tests -nomake examples -android-ndk <path/to/ndk> -android-sdk <path/to/sdk> -android-toolchain-version <e.g. 4.8> -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples
On Windows:
configure.bat -developer-build -platform win32-g++ -xplatform android-g++ -android-ndk <ANDROID_NDK_ROOT> -android-sdk <ANDROID_SDK> -opensource -confirm-license -nomake tests -nomake examples -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples
Note: If you want to use OpenSSL in your application, use the -openssl option with your configure command to build Qt binaries with runtime support for OpenSSL. For more information about how to add OpenSSL support to your application, see Adding OpenSSL Support.
- Start the build by using the make or mingw32-make (on Windows) utility with the -j<N> switch (used to speedup building).
The binaries are installed to the qtbase/bin directory by default for the developer builds. You can check the install paths using the qmake -query command.
Configuring Qt Creator
After installing the Qt for Android binaries either using the installer or by cross-compiling, Qt Creator must be configured to start developing your first Qt application for Android.
Note: You must install Qt Creator separately (either using the stand-alone or Qt 5 installer provided by Qt project, or by building it from the source) if you built the Qt 5.x binaries from the sources. Use the 3.0 git branch if you are building it from the source.
See Qt Creator Manual for instructions to configure and test your setup by creating a simple Qt Quick application. You can also try running an example on the Android target to test the setup. Use the android keyword in the search field under the Examples tab in Qt Creator Welcome mode to list all the examples tested for Android.