- Qt 6.8
- Qt for Android - Building from Source
- Qt 6.8.2 Reference Documentation

How Qt for Android Works ◦ Building Qt for Android Projects from Command Line

# Qt for Android - Building from Source

This page describes the process of configuring and building Qt for Android. To download and install a pre-built Qt for Android, follow the instructions on the Getting Started with Qt page.

## Prerequisites

To build Qt for Android from source please ensure all requirements from Getting Started with Qt for Android are met before continuing.

### Windows

Building Qt for Android on Windows also requires the following software:

- Mingw-w64 13.1 toolchain

Note: Qt for Android does not support building from source with Microsoft Visual C++ (MSVC).

Install the prerequisites and append their binary paths to the system `PATH`:

     set MINGW_ROOT=<MINGW_ROOT_PATH>\bin
     set PATH=%MINGW_ROOT%;%PATH%

To verify the installation, run:

     where mingw32-make.exe

The command should list mingw32-make.exe under the path <MINGW_ROOT> first.

## Getting the Sources

You can download the Qt sources from the Qt Downloads page, or follow the wiki guide for Getting the source code.

## Configuring

With Qt 6, you can build Qt for Android from source code using `CMake`. Qt 6 for Android requires a host Qt build, which means to build Qt for Android, you need to build Qt for the desktop platform used as a host (that is, Linux, macOS, or Windows).

To configure and do a minimalistic host build to be used with Qt for Android build, use the following command:

     mkdir ~/dev/build-host
     cd ~/dev/build-host
     ./configure -developer-build -nomake tests -nomake examples
     cmake --build . --target host_tools

That will configure a developer build for your host and only build the necessary dependencies used for the Android build. For more information on doing a full and more customizable build for your host, see Building Qt Sources.

To configure Qt for Android, create a shadow build directory to keep the source directory clean:

     mkdir -p ~/dev/build-qt-android
     cd ~/dev/build-qt-android

Qt for Android supports the following device architectures (ABIs): `arm64-v8a`, `x86_64`, `x86`, and `armeabi-v7a`

And then run the configure script:

     ./configure -prefix <install_path> -qt-host-path <qt_host_path> \
         -android-abis <abi> -android-sdk ~/Android/Sdk -android-ndk ~/Android/Sdk/ndk/26.1.10909125

The Android SDK is commonly installed by Qt Creator or Android Studio in the following locations:

- Linux: ~/Android/Sdk/
- macOS: ~/Library/Android/sdk/
- Windows: C:\Users\<USER>\AppData\Local\Android\Sdk\

Note: configure always uses the Ninja generator and build tool if a `ninja` executable is available. Ninja is cross-platform, feature-rich, performant, and recommended on all platforms. The use of other generators might work but is not officially supported.

## Advanced Configure Arguments

Qt for Android contains Java code which is compiled into *.jar files with the javac compiler. To set the javac version for source and target, use -android-javac-source and -android-javac-target respectively:

     -android-javac-source 8 -android-javac-target 8

To build Qt as a developer build instead of a prefix build, use the following instead of the `-prefix` argument:

     -developer-build

Note: When using this configure argument, it's not required to install your Qt build, Qt for Android can be used directly from within the build directory.

Qt Configure Options contains more information about the configure options.

## Building

To build Qt, run the following command:

     cmake --build . --parallel

## Installing

For prefix builds, to install Qt, run the following command:

     cmake --install .

On Unix, if you haven't provided the `-prefix <install_path>` configure option, the installation is placed under `/usr/local/Qt-<version>`, in that case, you would need to use `sudo` with the install command.

How Qt for Android Works ◦ Building Qt for Android Projects from Command Line