QT_ANDROID_GRADLE_MULTI_MODULE
从多模块 Gradle 项目构建 Android 包。
该变量于 Qt 6.12 版本中引入。
注意:该 变量目前处于技术预览阶段,未来版本中可能会发生变化。
注意: 仅当目标平台为 Android 时,才会使用此 变量。
将此变量设置为TRUE ,可从一个 Gradle 项目打包应用程序,该项目中每个 Android 工件对应一个模块,包含一个用于应用程序的app 模块以及每个动态功能对应的独立模块:
<build>/android-build-<target>/
app/ # the application module
<feature_1_target>/ # Dynamic feature 1
<feature_2_target>/ # Dynamic feature 2
settings.gradle # includes app and other dynamic features功能模块是Play Feature Delivery的构建基础,因此qt_add_android_dynamic_features() 需要此变量,请参阅qt_add_android_dynamic_feature_java_source_dirs。有关使用该功能的完整项目示例,请参阅《使用 Play Feature Delivery》。
注意: 动态功能目前尚不支持多 ABI。
在配置项目时设置该变量:
qt-cmake -S <source_dir> -B <build_dir> -DQT_ANDROID_GRADLE_MULTI_MODULE=ON或在调用qt_add_executable()之前尽早设置该变量,以便在创建可执行文件之前就确定该值:
set(QT_ANDROID_GRADLE_MULTI_MODULE ON)该变量还决定了如何构建该包。默认情况下,CMake 会生成一个部署配置文件,并将其余工作交由androiddeployqt 处理——后者负责解析 Qt 依赖项、将其复制到构建目录中,并从该目录运行 Gradle。 启用该变量后,CMake 会将依赖项的部署作为常规构建步骤自行处理,并为每个模块生成 Gradle 文件。随后,apk 和aab 目标会直接运行 Gradle,整个过程中完全不涉及 androiddeployqt。 应用程序将从android-build-<target>/app 进行打包,而部署的文件即为该包的构建依赖项。由于该选项依赖于 CMake 构建图,且无需额外部署工具,因此通常速度更快、操作更简单。
该变量自 Qt 6.11 起以QT_USE_ANDROID_MODERN_BUNDLE 的形式提供。该名称自 Qt 6.12 起已弃用,但如果已设置,系统仍会予以支持。
另请参阅 QT_USE_TARGET_ANDROID_BUILD_DIR和qt_add_android_dynamic_feature_java_source_dirs()。
© 2026 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.