用于用户项目的Android Multi-ABI版本又回来了

Android Multi-ABI builds for user projects are back

用于用户项目的Android Multi-ABI版本又回来了

Tuesday March 01, 2022 by Alexey Edelev | Comments

​2022年3月1日星期二Alexey Edelev | 评论

In Qt 6.3, we have restored support for multi-ABI builds for user applications that use CMake. The build procedure for Qt 6 has undergone significant changes, especially with regards to Qt for Android. Let's have a look at how to work with the multi-ABI builds in Qt 6.

在Qt 6.3中,我们为使用CMake的用户应用程序恢复了对多ABI构建的支持。Qt 6的构建过程已经发生了重大变化,尤其是对于Android的Qt。让我们看看如何在Qt6中使用多ABI构建。

First of all, it's recommended to use the recent CMake version to support latest features. As you probably noticed, Qt for Android uses DEFER calls, so multi-ABI builds rely on this feature as well. If you are stuck on CMake versions older than 3.19, check out the note at the end of this post.

​首先,建议使用最新的CMake版本来支持最新的功能。正如您可能注意到的,Qt for Android使用延迟调用,因此多ABI构建也依赖于此功能。如果你被3.19以上的CMake版本卡住了,请查看本文末尾的注释。

To configure your project, you need to run the bin/qt-cmake script from any of the available Qt for Android directories and use one of the ways to enable the multi-ABI build described below. The ABI of this primary Qt for Android will be used to set up and build the secondary ABIs and generate the final Android package. The build routine uses CMake ExternalProject for each secondary ABI under the hood.

​要配置项目,您需要从任何可用的qt for Android目录运行bin/qt cmake脚本,并使用以下方法之一启用多ABI构建。Qt for Android的主ABI将用于设置和构建次要ABI,并生成最终的Android软件包。构建例程使用CMake ExternalProject为每个次要ABI创建高级选项。

Set QT_ANDROID_BUILD_ALL_ABIS to detect them all

设置QT_ANDROID_BUILD_ALL_ABIS以检测它们

The easiest way to enable multi-ABI build is to set the CMake option QT_ANDROID_BUILD_ALL_ABIS to 'ON' at the project configuring stage. This option automatically detects available Qt for Android ABIs and uses them to build the Android package.

启用多ABI构建的最简单方法是在项目配置阶段将CMake选项QT_ANDROID_build_ALL_ABI设置为“ON”。该选项自动检测Qt for Android的可用ABI,并使用它们构建Android软件包。

For successful autodetection, each secondary ABI requires the presence of the related Qt for Android directory at the same directory level as the primary ABI, assuming the use of the default directory structure supplied by the Qt installer:

为了成功地进行自动检测,每个次要ABI都需要在与主ABI相同的目录级别上存在相关的Qt For Android目录,前提是使用Qt安装程序提供的默认目录结构:

/home/user/Qt/6.3.0
    android_armv7
    android_arm64_v8a
    android_x86
    android_x86_64
    ...

QT_ANDROID_ABIS to be a little more precise

QT_ANDROID_ABIS更精确一点

The most common way to build packages with multiple ABIs is to use the QT_ANDROID_ABIS CMake cache variable. This variable gives you the ability to build Android packages with a specific set of ABIs.

构建包含多个ABI的包的最常见方法是使用QT_ANDROID_ABIS的CMake缓存变量。这个变量使您能够使用一组特定的ABI构建Android软件包。

Note that in Qt 6.3.0, the primary ABI is added to the list of used ABIs unconditionally, without the ability to exclude it from the build.
请注意,在Qt 6.3.0中,主ABI无条件地添加到已用ABI列表中,无法将其从构建中排除。

QT_ANDROID_ABIS can take one of the following values supported by Qt 6: armeabi-v7aarm64-v8ax86x86_64.

QT_ANDROID_ABIS可以采用QT 6支持的以下值之一:armeabi-v7a、arm64-v8a、x86、x86_64。

The command below will configure the project to build packages using armeabi-v7aarm64-v8a and x86_64(see the note) ABIs:

​下面的命令将配置项目,以使用armeabi-v7a、arm64-v8a和x86_64(请参见注释)ABI构建包:

/home/user/Qt/Qt6.3.0/android_x86_64/bin/qt-cmake \
    -DQT_ANDROID_ABIS="armeabi-v7a;arm64-v8a" \
    -S <source_directory> -B <build_directory>

The /home/user/Qt/Qt6.3.0/android_armv7 and /home/user/Qt/Qt6.3.0/android_arm64_v8a directories are supossed to contain Qt for Android for respective secondary ABIs.

输入/home/user/Qt/Qt6.3.0/android_armv7/home/user/Qt/Qt6.3.0/android_arm64_v8a支持目录,以包含适用于Qt for Android的各个次要ABI。

Using the CMake cache variables QT_PATH_ANDROID_ABI_<ABI>, you can specify the absolute path to custom Qt for Android for each secondary ABIs. For instance:

使用CMake缓存变量QT_PATH_ANDROID_ABI_<ABI>,可以为每个Qt for Android的次要ABI指定自定义绝对路径。例如:

/home/user/Qt/Qt6.3.0/android_x86_64/bin/qt-cmake \
    -DQT_ANDROID_ABIS="armeabi-v7a;arm64-v8a" \
    -DQT_PATH_ANDROID_ABI_armeabi-v7a="<Qt/for/armeabi-v7a>" \
    -DQT_PATH_ANDROID_ABI_arm64-v8a="<Qt/for/arm64-v8a>" \
    -S <source_directory> -B <build_directory>

These variables can be used with the QT_ANDROID_BUILD_ALL_ABIS flag too:

这些变量也可以与QT_ANDROID_BUILD_ALL_ABIS标志一起使用:

/home/user/Qt/Qt6.3.0/android_x86_64/bin/qt-cmake \
    -DQT_ANDROID_BUILD_ALL_ABIS=ON \
    -DQT_PATH_ANDROID_ABI_armeabi-v7a="<Qt/for/armeabi-v7a>" \
    -DQT_PATH_ANDROID_ABI_arm64-v8a="<Qt/for/arm64-v8a>" \
    -S <source_directory> -B <build_directory>

Specify ABIs for a single target

为单个目标指定ABI

Yet another way to build a single package with multiple ABIs is to set the ANDROID_ABIS property for the executable target. The property has the highest priority among all the described methods. This way has very limited use, but it can still be applied for some projects.

构建包含多个ABI的单个包的另一种方法是为可执行目标设置ANDROID_ABIs属性。在所有描述的方法中,该属性的优先级最高。这种方法的用途非常有限,但仍然可以应用于某些项目。

# Build for arm64-v8a
set_property(TARGET androidapp PROPERTY ANDROID_ABIS "arm64-v8a")
if(BUILD_FOR_X86_TOO)
    set_property(TARGET androidapp APPEND PROPERTY ANDROID_ABIS "x86")
endif()

The primary ABI will be included regardless of entry into the ABIs list.

​无论是否进入ABI列表,主要ABI都将包括在内。

For users of older CMake versions

适用于旧版CMake的用户

If you use the CMake version older than 3.19, you need to finalize executable targets manually to make the multi-ABI magic work:

如果您使用的CMake版本早于3.19,则需要手动完成可执行目标,以使多ABI设置生效:

qt_add_executable(androidapp MANUAL_FINALIZATION main.cpp)
# Build for arm64-v8a, x86 only
set_target_properties(androidapp PROPERTIES ANDROID_ABIS "arm64-v8a;x86")
# ...
qt_finalize_target(androidapp)

Enable multi-ABI builds in QtCreator

在QtCreator中启用多ABI生成

The described methods for building multi-ABI packages can be used with QtCreator. The QT_ANDROID_BUILD_ALL_ABIS, QT_ANDROID_ABIS, and QT_PATH_ANDROID_ABI_<ABI> variables can be found in corresponding to the project Build Settings menu:

所描述的构建多ABI包的方法可与QtCreator一起使用。QT_ANDROID_BUILD_ALL_ABIS、QT_ANDROID_ABIS和QT_PATH_ANDROID_ABI<ABI>变量可在对应于项目构建设置菜单中找到:


We keep improving Android experience in Qt 6.

我们在Qt 6中不断改进Android体验。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值