CMAKE文件添加ANDROID相关设置
SET(QT_DIR ## Qt安装路径的环境变量
${QT_DIR} CACHE PATH "Qt root path"
)
IF("${QT_DIR}" STREQUAL "")
MESSAGE(FATAL_ERROR "Please set the Qt install path first. -DQT_DIR=XXXX ")
ENDIF()
#set(QT_DIR "D:/Qt/Qt5.12.0/5.12.0/android_x86")
if("${QT_DIR}" MATCHES "android_arm64_v8a")
set(ANDROID_ABI arm64-v8a)
elseif("${QT_DIR}" MATCHES "android_armv7")
set(ANDROID_ABI armeabi-v7a)
elseif("${QT_DIR}" MATCHES "android_x86")
set(ANDROID_ABI x86)
elseif()
message(ANDROID_ABI is not set)
endif()
IF(NOT ("${ANDROID_ABI}" STREQUAL ""))
if($ENV{ANDROID_NDK})
# 没有找到JAVA_HOME环境变量
message(FATAL_ERROR "not defined environment variable:ANDROID_NDK")
endif()
set(ANDROID_NDK $ENV{ANDROID_NDK})
message(ANDROID_NDK:${ANDROID_NDK})
#set(ANDROID_NDK D:/Android/android-ndk-r20-windows-x86_64/android-ndk-r20)
set(CMAKE_TOOLCHAIN_FILE ${ANDROID_NDK}/build/cmake/android.toolchain.cmake)
set(CMAKE_MAKE_PROGRAME ${ANDROID_NDK}/prebuilt/windows-x86_64/bin/make.exe)
set(ANDROID_TOOLCHAIN clang)
set(ANDROID_PLATFORM android-24)
set(ANDROID_STL c++_shared)
set(ANDROID_SYSROOT ${ANDROID_NDK}/sysroot)
set(INSOURCEBUILD 1)
set(Qt5_DIR "${QT_DIR}/lib/cmake/Qt5")
set(Qt5Core_DIR "${QT_DIR}/lib/cmake/Qt5Core")
set(Qt5Gui_DIR "${QT_DIR}/lib/cmake/Qt5Gui")
set(Qt5Widgets_DIR "${QT_DIR}/lib/cmake/Qt5Widgets")
set(Qt5Sql_DIR "${QT_DIR}/lib/cmake/Qt5Sql")
set(Qt5WebEngine_DIR "${QT_DIR}/lib/cmake/Qt5WebEngine")
set(Qt5WebEngineWidgets_DIR "${QT_DIR}/lib/cmake/Qt5WebEngineWidgets")
set(Qt5WebChannel_DIR "${QT_DIR}/lib/cmake/Qt5WebChannel")
set(Qt5Network_DIR "${QT_DIR}/lib/cmake/Qt5Network")
set(Qt5WebSockets_DIR "${QT_DIR}/lib/cmake/Qt5WebSockets")
set(Qt5Concurrent_DIR "${QT_DIR}/lib/cmake/Qt5Concurrent")
set(Qt5Quick_DIR "${QT_DIR}/lib/cmake/Qt5Quick")
# set(ANDROID_ABI x86)
if(${ANDROID_ABI} STREQUAL "armeabi-v7a")
set(ANDROID_ABI_NAME "android_armv7")
MESSAGE( "is armeabi-v7a")
include_directories(${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)
elseif(${ANDROID_ABI} STREQUAL "arm64-v8a")
MESSAGE( "is arm64-v8a")
set(ANDROID_ABI_NAME "android_arm64_v8a")
include_directories(${ANDROID_SYSROOT}/usr/include/aarch64-linux-android)
elseif(${ANDROID_ABI} STREQUAL "x86")
MESSAGE( "is x86")
set(ANDROID_ABI_NAME "android_x86")
include_directories(${ANDROID_SYSROOT}/usr/include/i686-linux-android)
else()
MESSAGE( "is else")
set(ANDROID_ABI_NAME "android_x86")
include_directories(${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)
endif()
endif()
拷贝so库依赖文件
在编译好的SO库目录下创建json文件
json 文件名:android-libtest.so-deployment-settings.json
{
"description": "This file is generated by qmake to be read by androiddeployqt and should not be modified by hand.",
"qt": "D:/Qt/Qt5.12.0/5.12.0/android_x86",
"sdk": "C:/Users/HiWin10/AppData/Local/Android/Sdk",
"sdkBuildToolsRevision": "29.0.2",
"ndk": "D:\\Android\\android-ndk-r20-windows-x86_64\\android-ndk-r20",
"toolchain-prefix": "x86",
"tool-prefix": "i686-linux-android",
"toolchain-version": "4.9",
"ndk-host": "windows-x86_64",
"target-architecture": "x86",
"android-platform":"android-24",
"ant":"D:\\Android\\apache-ant-1.10.7-bin\\apache-ant-1.10.7\\bin\\ant.bat",
"stdcpp-path": "D:\\Android\\android-ndk-r20-windows-x86_64\\android-ndk-r20/sources/cxx-stl/llvm-libc++/libs/x86/libc++_shared.so",
"install_root":"D:/dart_demo/export/lib/x86/output",
"application-binary": "D:/dart_demo/export/lib/x86/libtest.so"
}
拷贝so库依赖文件
打开cmd,输入
“D:\Qt\Qt5.12.0\5.12.0\android_x86\bin\androiddeployqt.exe” --input D:\dart_demo\export\lib\x86\android-libtest.so-deployment-settings.json --output D:\dart_demo\export\lib\x86\output
ok