创建文件:android_gen.sh,内容如下:
#!/bin/bash
echo "start build android"
#手动设置开始
CMAKE_DIR=yourpath/Android/Sdk/cmake/3.18.1
NDK_DIR=yourpath/Android/Sdk/ndk/21.4.7075529
SDK_DIR=yourpath/Android/Sdk
#手动设置结束
#cmake_exec=$CMAKE_DIR/bin/cmake
cmake_exec=cmake
#ninja_exec=$CMAKE_DIR/bin/ninja
ninja_exec=ninja
cur_dir=$(pwd)
echo $cmake_exec
echo $ninja_exec
echo $cur_dir
if [[ ! -f $cur_dir/CMakeLists.txt ]]; then
echo "check CMakeLists.txt"
exit
fi
out_dir=$cur_dir/build_android
libout_dir=$cur_dir/Jnilibs
H_dir=$cur_dir
B_dir=$cur_dir/build_android
#TARGET=armeabi-v7a
TARGET=arm64-v8a
ANDROID_ABI="arm64-v8a"
ANDROID_NDK="yourpath/Android/Sdk/ndk/21.4.7075529"
CMAKE_LIBRARY_OUTPUT_DIRECTORY=$libout_dir/$TARGET/
CMAKE_BUILD_TYPE=Release
CMAKE_MAKE_PROGRAM=$ninja_exec
CMAKE_TOOLCHAIN_FILE=$NDK_DIR/build/cmake/android.toolchain.cmake
ANDROID_NATIVE_API_LEVEL=24
ANDROID_TOOLCHAIN=clang
CMAKE_GENERATOR="Ninja"
$cmake_exec -H$H_dir -B$B_dir \
-DANDROID_ABI=${ANDROID_ABI} \
-DANDROID_NDK=${ANDROID_NDK} \
-DANDROID_NDK_HOST_X64="YES" \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$CMAKE_LIBRARY_OUTPUT_DIRECTORY \
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
-DCMAKE_MAKE_PROGRAM=ninja \
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} \
-DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_API_LEVEL} \
-DANDROID_TOOLCHAIN=${ANDROID_TOOLCHAIN} \
-DCMAKE_GENERATOR=${CMAKE_GENERATOR} \
cd $out_dir
$ninja_exec
cd $cur_dir
#rm -rf $out_dir
保存后执行 ./android_gen.sh
生成: open62541.a