Android编译第三方库脚本模板

#!/bin/bash
path_current=`pwd`
path_script=$(cd "$(dirname "$0")"; pwd)

DEFAULT_PATH=$PATH
ANDROID_NDK_HOME=~/Android/Sdk/ndk/20.1.5948944

declare -A qt_architectures=( ["x86_64"]="x86_64" ["x86"]="x86" ["arm64"]="arm64-v8a" ["arm"]="armeabi-v7a" )
rm -rf android
if [ ! -d "${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin" ]; then
    echo "failed to find linux-x86_64 home. please install ndk-r20+ version in ubuntu-18.04 system"
    exit 1
fi
ANDROID_TOOLCHAIN="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin"
for arch in ${!qt_architectures[@]}
do    
    case $arch in
        arm)
            ANDROID_API=16
            ;;
        x86)
            ANDROID_API=16
            ;;
        arm64)
            ANDROID_API=21
            ;;
        x86_64)
            ANDROID_API=21
            ;;
    esac
    rm -rf ${path_script}/build

    ANDROID_DEFINITION="-DCMAKE_FIND_ROOT_PATH:PATH=${path_script}/../openssl/android/${arch};${path_script}/../zlib/android/${arch}"
    ANDROID_DEFINITION="${ANDROID_DEFINITION} -DWITH_EXAMPLES=OFF"
    ANDROID_DEFINITION="${ANDROID_DEFINITION} -DCMAKE_BUILD_TYPE:STRING=Release"
    ANDROID_DEFINITION="${ANDROID_DEFINITION} -DANDROID_ABI:STRING=${qt_architectures[$arch]}"
    ANDROID_DEFINITION="${ANDROID_DEFINITION} -DANDROID_NATIVE_API_LEVEL:STRING=${ANDROID_API}"
    ANDROID_DEFINITION="${ANDROID_DEFINITION} -DANDROID_NDK:PATH=${ANDROID_NDK_HOME}"
    ANDROID_DEFINITION="${ANDROID_DEFINITION} -DCMAKE_CXX_COMPILER:STRING=${ANDROID_TOOLCHAIN}/clang++"
    ANDROID_DEFINITION="${ANDROID_DEFINITION} -DCMAKE_C_COMPILER:STRING=${ANDROID_TOOLCHAIN}/clang"
    ANDROID_DEFINITION="${ANDROID_DEFINITION} -DCMAKE_TOOLCHAIN_FILE:PATH=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake"
    mkdir -p ${path_script}/build && cd ${path_script}/build && cmake -DCMAKE_C_FLAGS="-fPIC -Wall" -DCMAKE_INSTALL_PREFIX=${path_script}/android/${arch} ${ANDROID_DEFINITION} ../libssh-0.9.3
    make clean && make && make install
done