1. 下载Android NDK ,设置Android NDK 环境变量
export ANDROID_NDK_HOME=/home/your-account/Android/Sdk/ndk-bundle
Or:
export ANDROID_NDK_HOME=/home/your-account/Android/android-ndk-r21b
windows平台直接添加ANDROID_NDK_HOME环境变量
2. 安装vcpkg
https://github.com/microsoft/vcpkg.git
clone后运行bootstrap-vcpkg.bat 编译 vcpkg.exe
3. 导入android配置cmake文件
在triplets/community/ 文件夹下创建以下四个cmake文件
- arm-android.cmake
set(VCPKG_TARGET_ARCHITECTURE arm)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
- arm64-android.cmake
set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
- x86-android.cmake
set(VCPKG_TARGET_ARCHITECTURE x86)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
- x64-android.cmake
set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
至此,配置完成!
4.编译不同平台参考以下命令
VCPKG_TARGET_TRIPLET | ANDROID_ABI |
---|---|
arm64-android | arm64-v8a |
arm-android | armeabi-v7a |
x64-android | x86_64 |
x86-android | x86 |
5. 示例
编译不同架构的sqlite3库
- arm64-v8a
vcpkg install sqlite3:arm64-android --debug //添加--debug能够看到详细的编译信息
- armeabi-v7a
vcpkg install sqlite3:arm-android
- x86_64
vcpkg install sqlite3:x64-android
- x86
vcpkg install sqlite3:x86-android
在 installed\ 目录下能看到编译好的库
6 参考
-
https://vcpkg.readthedocs.io/en/latest/users/android/
-
https://docs.microsoft.com/zh-cn/cpp/build/vcpkg-command-line-reference?view=msvc-160