QT_ANDROID_EXTRA_LIBS

需随目标一起部署的附加库。

该属性自 Qt 6.0 起引入。

注意: 仅当目标平台为 Android 时,才使用此 属性。

一个外部库列表,这些库将被复制到应用程序的libs 文件夹中,并在启动时加载。例如,这可用于在应用程序中启用 OpenSSL。有关更多信息,请参阅《为 Android 添加 OpenSSL 支持》。

从项目的构建树中添加额外库时,还必须在库与应用程序目标之间建立依赖关系。如果采用以下项目结构,在部署 APK 时可能会出现问题:

qt_add_executable(MyApp main.cpp)

set_target_properties(MyApp PROPERTIES
    QT_ANDROID_EXTRA_LIBS
        ${CMAKE_CURRENT_BINARY_DIR}/libMyService_${ANDROID_ABI}.so
)

# MyService library doesn't have any relations with MyApp
qt_add_library(MyService service.cpp)

这会导致无法确定在部署 MyApp 之前 MyService 库是否可用。最简单的解决方案是将 MyService 库添加到 MyApp 的依赖项中:

add_dependencies(MyApp MyService)

在向多 ABI 项目添加特定于架构的库时,应显式列出所有路径,而不是依赖CMAKE_ANDROID_ARCH_ABI 等变量来动态计算路径。

建议:

set(libs
    ${CMAKE_CURRENT_BINARY_DIR}/libA_x86so
    ${CMAKE_CURRENT_BINARY_DIR}/libA_x86_64.so
    ${CMAKE_CURRENT_BINARY_DIR}/libA_arm64-v8a.so
    ${CMAKE_CURRENT_BINARY_DIR}/libA_armeabi-v7a.so
)
set_target_properties(MyApp PROPERTIES QT_ANDROID_EXTRA_LIBS ${libs})

# When targeting precompiled libs
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC libA_${ANDROID_ABI})

而非:

set_target_properties(MyApp PROPERTIES
    QT_ANDROID_EXTRA_LIBS
        ${CMAKE_CURRENT_BINARY_DIR}/libA_${CMAKE_ANDROID_ARCH_ABI}.so)

另请参阅 qt_android_generate_deployment_settings()。

© 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.