To build CMake projects with an installed Qt, for example, for Linux use the following with qt-cmake wrapper:
~/Qt/<qt_version>/android_<abi>/bin/qt-cmake \
    -DANDROID_SDK_ROOT=~/Android/Sdk \
    -DANDROID_NDK_ROOT=~/Android/Sdk/ndk/26.1.10909125 \
    -S <source_dir> -B <build_dir> \
    -GNinja
					
					Throughout this page, we use the Android SDK path for Linux for simplicity, however, when issuing these commands, make sure to use your system's relevant path.
The Android SDK is commonly installed by Qt Creator or Android Studio in the following locations:
注意: 若正使用 a self-built Qt, you don't need to provide the SDK and NDK arguments, as the same values used for building Qt are used with qt-cmake .
						In Qt 6.7, several ways exist to build a multi-ABI package. By default, only the single ABI belonging to the
						
							qt-cmake
						
						script is selected. Setting the
						
							QT_ANDROID_BUILD_ALL_ABIS
						
						变量到
						
TRUE
						
						enables the automatic detection of available Qt for Android SDKs. The detection mechanism assumes the use of the default directory structure supplied by Qt Online Installer:
					
~/Qt/<qt_version>:
    android_arm64_v8a
    android_armv7
    android_x86
    android_x86_64
					
					The command below shows the easiest way to build an Android multi-ABI package using the Qt for Android SDKs supplied by Qt Online Installer:
~/Qt/<qt_version>/android_<abi>/bin/qt-cmake \
    -DQT_ANDROID_BUILD_ALL_ABIS=TRUE \
    -DANDROID_SDK_ROOT=~/Android/Sdk \
    -DANDROID_NDK_ROOT=~/Android/Sdk/ndk/26.1.10909125 \
    -S <source_directory> -B <build_directory>
    -GNinja
					
					
						使用
						
							QT_ANDROID_ABIS
						
						variable, it's possible to customize the list of ABIs the project is built for. The corresponding Qt for Android development kits needs to follow the directory structure described previously. The following command line configures a project for
						
arm64-v8a
						
						and
						
x86
						
						ABIs only:
					
~/Qt/<qt_version>/android_<abi>/bin/qt-cmake \
    -DQT_ANDROID_ABIS="arm64-v8a;x86" \
    -DANDROID_SDK_ROOT=~/Android/Sdk \
    -DANDROID_NDK_ROOT=~/Android/Sdk/ndk/26.1.10909125 \
    -S <source_directory> -B <build_directory>
    -GNinja
					
					注意: The ABI of the primary SDK that qt-cmake script belongs to is added to the list of used ABIs unconditionally. It's not possible to exclude it from the build.
注意: QT_ANDROID_BUILD_ALL_ABIS 拥有更高优先级相比 QT_ANDROID_ABIS .
Paths to the Qt for Android SDKs that do not match the default directory structure can be changed using the corresponding QT_PATH_ANDROID_ABI_<ABI> 变量。
						The following example enables the automatic detection of available Qt for Android SDKs and specifies custom paths to
						
armeabi-v7a
						
						and
						
arm64-v8a
						
						SDKs:
					
<qt_for_android_install_path>/bin/qt-cmake \
    -DQT_ANDROID_BUILD_ALL_ABIS=TRUE
    -DQT_PATH_ANDROID_ABI_armeabi-v7a="<Qt/for/armeabi-v7a>" \
    -DQT_PATH_ANDROID_ABI_arm64-v8a="<Qt/for/arm64-v8a>" \
    -DANDROID_SDK_ROOT=~/Android/Sdk \
    -DANDROID_NDK_ROOT=~/Android/Sdk/ndk/26.1.10909125 \
    -S <source_directory> -B <build_directory>
    -GNinja
					
					It's also possible to set the QT_ANDROID_ABIS target property that specifies a list of ABIs that the single executable target is built for. For example:
qt_add_executable(MyApp main.cpp) set_target_properties(MyApp PROPERTIES QT_ANDROID_ABIS "arm64-v8a;x86")
						The
						
MyApp
						
						target will be built for
						
armeabi-v7a
						
						and
						
arm64-v8a
						
						only, even if the
						
QT_ANDROID_BUILD_ALL_ABIS
						
						or
						
QT_ANDROID_ABIS
						
						variable is set.
					
Once the project is configured, you may use the following CMake targets to create the application bundle:
cmake --build . --target apk
Or to generate the AAB:
cmake --build . --target aab
						Under the hood, your Qt code is built and copied to the
						
android-build
						
						directory, then
						
							Gradle
						
						is used to build the Java code and package the application.
					
If an APK intended for release is built, then it should be signed. For more information on signing the package with Qt Creator, see Signing Android packages . Otherwise, check the CMake variables QT_ANDROID_SIGN_APK and QT_ANDROID_SIGN_AAB .
						可以继续使用
						
qmake
						
						构建用户工程如在 Qt 5。
					
						
							注意:
						
						Building multi-ABI packages with
						
qmake
						
						is not supported in Qt 6.
					
另请参阅 QT_ANDROID_ABIS , QT_ANDROID_BUILD_ALL_ABIS , QT_PATH_ANDROID_ABI_<ABI> ,和 QT_ANDROID_ABIS .
Qt for Android - 从源代码构建 移植到 Android