Qt for Android - 从源代码构建

此页面描述了配置和构建的过程,针对 Qt for Android . To download and install a pre-built Qt for Android, follow the instructions on the Qt 快速入门 页面。

先决条件

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 11.2 toolchain

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

Install the requirements, and set the PATH to include the newly installed binaries:

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> 首先。

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

Qt 6 allows building Qt for Android from source code using CMake . Qt 6 keeps the same configure script from Qt 5. The main difference is that Qt for Android is dependent on a host Qt build, which means to build Qt for Android, you need to build Qt for the desktop platform used as a host (for example Linux, macOS, or Windows).

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

mkdir <path_to_build_dir>/build-qt
cd <path_to_build_dir>/build-qt
					

And then run the configure script:

<path_to_qt_source>/configure -platform android-clang -prefix </path/to/install> -android-ndk $ANDROID_NDK_ROOT -android-sdk $ANDROID_SDK_ROOT -qt-host-path <path_to_host_qt_installation>
					

注意: 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.

体系结构

Qt for Android supports the following ABIs:

此 Qt 发行支持下列配置:

分发 体系结构 编译器 注意事项
Android 8.0 到 Android 13 (API 级别 26 到 API 33) armeabi-v7a , x86 , arm64-v8 ,和 x86_64 由 Google 提供的 Clang 14.0.6 (NDK r25b) 对于 JDK 版本见 JDK (Java 开发工具包)

注意: It's recommended that Qt user apps use the same NDK r25b version used for building these official Qt for Android libraries. An NDK version more recent than r23b is required if building a project results in an error of missing the symbols for __emutls_get_address .

To choose the ABI to build for, use the -android-abis feature of the configure script.

注意: 6.6 does not yet support being built for multiple ABIs at the same time.

Advanced Configure Arguments

Qt for Android contains Java code which is compiled into *.jar files with javac . 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 -prefix 自变量:

-developer-build
					

Qt 配置选项 contains more information about the configure options.

Building

To build the configured Qt code, run the following command:

cmake --build . --parallel
					

Installing

Now, to install Qt, run the following command:

cmake --install .
					

On Unix based OSes you should prefix the install command with the sudo 命令。

If you haven't provided the --prefix <install-dir> configure option, the installation is placed under /usr/local/Qt-<version> .

Getting Started with Qt for Android Qt for Android - Building User Projects