Qt for Android - Building from Source
You can download the Qt 5 sources from the Downloads page. For more information, visit the Getting Started with Qt page.
Qt for Android has some requirements that are described in more detail in Getting Started with Qt for Android.
Installing the Android SDK and NDK on Linux
On Linux, you can install the Android SDK and NDK in one of two ways:
Scripted Installation
For any Debian-based Linux, use the following command:
apt install build-essential android-sdk
If you require openjdk, add default-jdk-headless
to the command above.
It's recommended to install the NDK using sdkmanager, with the following commands:
sdkmanager --verbose --licenses sdkmanager --update sdkmanager "platforms;android-28" "ndk-bundle" "build-tools;28.0.3" "platform-tools" "tools"
Manual Installation
- Download Android Studio from https://developer.android.com/studio/index.html.
- Open Android Studio and run the SDK Manager tool from Tools > Android > SDK Manager. If this toolbar isn't visible, you can enable it from the View menu: select Toolbar.
- Download the Android NDK from https://developer.android.com/tools/sdk/ndk/index.html.
Note: As of Qt 5.12, Android NDK r18 is required and gcc toolchains are no longer supported.
- Ensure that the NDK supports the API level you're targeting. To verify, check your path_to_NDK/platforms directory.
Note: As of Qt 5.13, any API level >= 21 is sufficient.
- Install a JDK with a version of 1.6 or newer from https://www.oracle.com/technetwork/java/javase/downloads/index.html. Alternatively, you can use OpenJDK.
apt-get install openjdk-8-jdk
Building Qt for Android on Linux
- If you have a commercially licensed Qt, install your license file. If you're using a binary installer or the commercial Qt Creator, your licenses are automatically fetched and stored in your local user profile:
$XDG_DATA_HOME/Qt/qtlicenses.ini
. Alternatively, you can download the respective license file from your Qt Account Web portal and save it to your user profile as$HOME/.qt-license
. If you prefer a different location or file name, you need to set theQT_LICENSE_FILE
environment variable to the respective file path. - Next, unpack the archive. If you have the
qt-everywhere-opensource-src-%VERSION%.tar.gz
package, type the following commands at a command line prompt:cd /tmp gunzip qt-everywhere-opensource-src-%VERSION%.tar.gz # uncompress the archive tar xvf qt-everywhere-opensource-src-%VERSION%.tar # unpack it
This creates the
/tmp/qt-everywhere-opensource-src-%VERSION%
directory containing the files from the archive. We only support the GNU version of thetar
archiving utility; also known asgtar
on some systems. - Configure the
JAVA_HOME
environment variable. You need to set it and add it to yourPATH
; preferably at the end of~/.profile
:export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 export PATH=$PATH:$JAVA_HOME/bin
- Next, configure Qt with the following command:
./configure -xplatform android-clang --disable-rpath -nomake tests -nomake examples -android-ndk <path/to/ndk> -android-sdk <path/to/sdk> -no-warnings-are-errors
You may provide the
-android-abis
parameter to limit the Android ABIs targeted, such as armeabi-v7a, arm64-v8a, x86, or x86_64:-android-abis armeabi-v7a,arm64-v8a
If the parameter is not specified, Qt is built for all supported ABIs.
- To build the parts of Qt you have now configured run the following command. nproc is optional, representing the number of parallel jobs your system can do.
make -j$(nproc)
- To install the parts of Qt you have built, run:
make install
If you haven't used the
--prefix <install-dir>
configure option, the installation is placed under/usr/local/Qt-<version>
. In Debian/Ubuntu, you should prefix themake
command with thesudo
command.
Installing the Android SDK and NDK on Windows
Note: Currently, it is not possible to use Microsoft's compilers to build the Windows host tools for Qt Android.
Step 1: Setting up the Development Environment
- Install the latest Perl from http://strawberryperl.com. Then, select a destination folder, also known as
PERL_ROOT
. - Set up the MinGW toolchain by downloading a pre-built Qt package for MinGW, and then add it to your
PATH
, for example:C:\dev\Qt\Tools\mingw730_64\bin
. - Install the latest JDK from https://www.oracle.com/technetwork/java/javase/downloads/index.html. Then, add the <JDK_ROOT> to
PATH
. Alternatively, if you've installed Android Studio, you can use the JDK that's included in your installation'sjre
folder. - Install the Android NDK, r18b, from https://developer.android.com/tools/sdk/ndk/index.html. Extract it to <ANDROID_NDK_PATH>.
- Install the latest Android SDK (tools only) from http://developer.android.com/sdk/index.html. Run the Android SDK Manager and install the latest version of "SDK Platform", "Google APIs", and "build-tools" in <ANDROID_SDK_PATH>.
- Open the
cmd.exe
window and verify that:where gcc.exe
lists <MINGW_ROOT>.exe first before <PERL_ROOT>.exe.where mingw32-make.exe
lists <MINGW_ROOT32>-make.exe first.where javac.exe
lists <JDK_ROOT> first.
- Add the following environment variables:
set "ANDROID_API_VERSION=android-28" set "ANDROID_SDK_ROOT=<ANDROID_SDK_PATH>" set "ANDROID_TARGET_ARCH=armeabi-v7a" set "ANDROID_BUILD_TOOLS_REVISION=21.1.2" set "ANDROID_NDK_PATH=<ANDROID_NDK_PATH>" set "ANDROID_TOOLCHAIN_VERSION=4.9"
Depending on which NDK you have downloaded, add its path:
set "ANDROID_NDK_HOST=windows-x86_64"
or
set "ANDROID_NDK_HOST=windows"
Building Qt for Android on Windows
- If you have a commercially licensed Qt, install your license file. If you're using a binary installer or the commercial Qt Creator, your licenses are automatically fetched and stored in your local user profile:
%USERPROFILE%\AppData\Roaming\Qt\qtlicenses.ini
. Alternatively, you can download the respective license file from your Qt Account Web portal and save it to your user profile as%USERPROFILE%\.qt-license
. If you prefer a different location or file name, you need to set theQT_LICENSE_FILE
environment variable to the respective file path. - Next, unpack the archive. Uncompress the files into the directory in which you want Qt installed, for example:
C:\Qt\%VERSION%
. This install path must not contain any spaces or Windows-specific file system characters. - Run the following command to configure Qt:
configure.bat -prefix <path to install Qt to> -platform win32-g++ -opengl es2 -xplatform android-clang -android-ndk %ANDROID_NDK_PATH% -android-sdk %ANDROID_SDK_ROOT% -nomake tests -nomake examples
- To build the previously configured parts of Qt, run the following command:
mingw32-make.exe -j<N>
<N> is optional, representing the number of parallel jobs your system can do.
- Now, to install Qt, run the following command:
mingw32-make.exe install
© 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.