Qt for Android - Building from Source | Qt 5.15

- Qt 5.15
- Qt for Android - Building from Source
- Qt 5.15.0 Reference Documentation

# Qt for Android - Building from Source

Qt for Android has some requirements that you are recommended to know before going through this guide. Accomplish the tasks in Getting Started with Qt for Android first.

You can download the Qt 5 sources from the Downloads page.

## Building on Linux

### Prepare the Build Environment

First, install the Android SDK in one of two ways:

- Using the package manager
- Using a manual installation

#### Using the Package Manager

For any Debian-based Linux, use the following command:

     sudo apt install build-essential android-sdk openjdk-11-jdk

It is recommended to install the Android 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"

Note: If you are using the old SDK Tools packages "tools", OpenJDK 1.8 is needed. It is also recommended to install the latest SDK Tools "cmdline-tools" package and switch to it.

#### Using Manual Installation

You can use Android Studio to download and installl the Android SDK packages required for developing applications for Android. For more information, see Android Studio documentation.

### Installing the License File

If you use Qt with a commercial license, the Qt tools look for a local license file. If you are 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` file).

If you do not use any binary installer or Qt Creator, 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 the `QT_LICENSE_FILE` environment variable to the respective file path.

### Unpacking the Archive

Unpack the archive if you have not done so already. For example, 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 directory `/tmp/qt-everywhere-opensource-src-%VERSION%` containing the files from the archive. We only support the GNU version of the tar archiving utility. Note that on some systems it is called gtar.

### Configuring and Building

Set the following environment variables, and add them to your `PATH`; preferably at the end of `~/.profile`:

     export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
     export PATH=$PATH:$JAVA_HOME/bin

To configure Qt for Android, run the following:

     cd /tmp/qt-everywhere-opensource-src-%VERSION%
     ./configure -xplatform android-clang --disable-rpath -nomake tests -nomake examples -android-ndk <path/to/sdk>/ndk-bundle/ -android-sdk <path/to/sdk> -no-warnings-are-errors

The Configure Options page contains more information about the configure options.

You may provide the `-android-abis` parameter to limit the Android ABIs being built, with either of: 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 configured Qt code, run the following command:

     make -j$(nproc)

Note: nproc is optional. It represents the number of parallel jobs your system can do.

Then install the built Qt for Android:

     make install

If you haven't provided the `--prefix <install-dir>` configure option, the installation is placed under `/usr/local/Qt-<version>`. In Debian/Ubuntu, you should prefix the `make` command with the `sudo` command.

## Building on Windows

First, you can use Android Studio to download and install the Android SDK packages required for developing applications for Android. For more information, see Android Studio documentation.

### Preparing the Build Environment

Install the following:

- Perl
- A JDK 1.8 package such as JDK or OpenJDK or AdoptOpenJDK.
- MinGW 7.3 toolchain

Then set the respective environment variables, replacing them with the appropriate values:

     set "JDK_ROOT=<JDK_ROOT_PATH>\bin\"
     set "MINGW_ROOT=<MINGW_ROOT_PATH>"
     set "PERL_ROOT=<PERL_ROOT_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.

Note: Currently, it is not possible to use Microsoft's compilers to build the Windows host tools for Qt Android.

### Setting a Commercial License

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 the `QT_LICENSE_FILE` environment variable to the respective file path.

### Building the Sources

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:

     cd <decompressed_source_code_folder>
     configure.bat -prefix <path to install Qt to> -platform win32-g++ -opengl es2 -xplatform android-clang -android-sdk <ANDROID_SDK_PATH> -android-ndk <ANDROID_SDK_PATH>\ndk-bundle\ -nomake tests -nomake examples

The Configure Options page contains more information about the configure options.

To build the configured Qt for Android code, run the following:

     mingw32-make.exe -j<N>

Note: <N> is optional. It represents the number of parallel jobs your system can do.

Now, to install Qt, run the following command:

     mingw32-make.exe install