rustdesk/flutter/build_android_deps.sh

88 lines
2.0 KiB
Bash
Raw Normal View History

2022-06-07 16:45:06 +08:00
#!/bin/bash
set -e -o pipefail
ANDROID_ABI=$1
# Build RustDesk dependencies for Android using vcpkg.json
2022-12-26 00:23:03 +08:00
# Required:
2022-06-07 16:45:06 +08:00
# 1. set VCPKG_ROOT / ANDROID_NDK path environment variables
# 2. vcpkg initialized
# 3. ndk, version: r25c or newer
2022-06-07 16:45:06 +08:00
if [ -z "$ANDROID_NDK_HOME" ]; then
echo "Failed! Please set ANDROID_NDK_HOME"
2022-06-07 16:45:06 +08:00
exit 1
fi
if [ -z "$VCPKG_ROOT" ]; then
echo "Failed! Please set VCPKG_ROOT"
exit 1
fi
2022-06-14 21:43:17 +08:00
API_LEVEL="21"
2022-06-07 16:45:06 +08:00
# Get directory of this script
SCRIPTDIR="$(readlink -f "$0")"
SCRIPTDIR="$(dirname "$SCRIPTDIR")"
# Check if vcpkg.json is one level up - in root directory of RD
if [ ! -f "$SCRIPTDIR/../vcpkg.json" ]; then
echo "Failed! Please check where vcpkg.json is!"
exit 1
fi
2022-06-14 21:43:17 +08:00
# NDK llvm toolchain
2022-06-14 21:43:17 +08:00
HOST_TAG="linux-x86_64" # current platform, set as `ls $ANDROID_NDK/toolchains/llvm/prebuilt/`
TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/$HOST_TAG
function build {
2022-12-26 00:23:03 +08:00
ANDROID_ABI=$1
2022-06-14 21:43:17 +08:00
case "$ANDROID_ABI" in
arm64-v8a)
ABI=aarch64-linux-android$API_LEVEL
VCPKG_TARGET=arm64-android
;;
armeabi-v7a)
ABI=armv7a-linux-androideabi$API_LEVEL
VCPKG_TARGET=arm-neon-android
;;
x86_64)
ABI=x86_64-linux-android$API_LEVEL
VCPKG_TARGET=x64-android
;;
x86)
ABI=i686-linux-android$API_LEVEL
VCPKG_TARGET=x86-android
;;
*)
echo "ERROR: ANDROID_ABI must be one of: arm64-v8a, armeabi-v7a, x86_64, x86" >&2
return 1
esac
echo "*** [$ANDROID_ABI][Start] Build and install vcpkg dependencies"
pushd "$SCRIPTDIR/.."
$VCPKG_ROOT/vcpkg install --triplet $VCPKG_TARGET --x-install-root="$VCPKG_ROOT/installed"
2022-06-14 21:43:17 +08:00
popd
echo "*** [$ANDROID_ABI][Finished] Build and install vcpkg dependencies"
if [ -d "$VCPKG_ROOT/installed/arm-neon-android" ]; then
echo "*** [Start] Move arm-neon-android to arm-android"
mv "$VCPKG_ROOT/installed/arm-neon-android" "$VCPKG_ROOT/installed/arm-android"
2022-06-14 21:43:17 +08:00
echo "*** [Finished] Move arm-neon-android to arm-android"
fi
2022-06-14 21:43:17 +08:00
}
2022-06-07 16:45:06 +08:00
if [ ! -z "$ANDROID_ABI" ]; then
build "$ANDROID_ABI"
else
echo "Usage: build-android-deps.sh <ANDROID-ABI>" >&2
exit 1
fi