build_android_deps.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. set -e -o pipefail
  3. ANDROID_ABI=$1
  4. # Build RustDesk dependencies for Android using vcpkg.json
  5. # Required:
  6. # 1. set VCPKG_ROOT / ANDROID_NDK path environment variables
  7. # 2. vcpkg initialized
  8. # 3. ndk, version: r25c or newer
  9. if [ -z "$ANDROID_NDK_HOME" ]; then
  10. echo "Failed! Please set ANDROID_NDK_HOME"
  11. exit 1
  12. fi
  13. if [ -z "$VCPKG_ROOT" ]; then
  14. echo "Failed! Please set VCPKG_ROOT"
  15. exit 1
  16. fi
  17. API_LEVEL="21"
  18. # Get directory of this script
  19. SCRIPTDIR="$(readlink -f "$0")"
  20. SCRIPTDIR="$(dirname "$SCRIPTDIR")"
  21. # Check if vcpkg.json is one level up - in root directory of RD
  22. if [ ! -f "$SCRIPTDIR/../vcpkg.json" ]; then
  23. echo "Failed! Please check where vcpkg.json is!"
  24. exit 1
  25. fi
  26. # NDK llvm toolchain
  27. HOST_TAG="linux-x86_64" # current platform, set as `ls $ANDROID_NDK/toolchains/llvm/prebuilt/`
  28. TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/$HOST_TAG
  29. function build {
  30. ANDROID_ABI=$1
  31. case "$ANDROID_ABI" in
  32. arm64-v8a)
  33. ABI=aarch64-linux-android$API_LEVEL
  34. VCPKG_TARGET=arm64-android
  35. ;;
  36. armeabi-v7a)
  37. ABI=armv7a-linux-androideabi$API_LEVEL
  38. VCPKG_TARGET=arm-neon-android
  39. ;;
  40. x86_64)
  41. ABI=x86_64-linux-android$API_LEVEL
  42. VCPKG_TARGET=x64-android
  43. ;;
  44. x86)
  45. ABI=i686-linux-android$API_LEVEL
  46. VCPKG_TARGET=x86-android
  47. ;;
  48. *)
  49. echo "ERROR: ANDROID_ABI must be one of: arm64-v8a, armeabi-v7a, x86_64, x86" >&2
  50. return 1
  51. esac
  52. echo "*** [$ANDROID_ABI][Start] Build and install vcpkg dependencies"
  53. pushd "$SCRIPTDIR/.."
  54. $VCPKG_ROOT/vcpkg install --triplet $VCPKG_TARGET --x-install-root="$VCPKG_ROOT/installed"
  55. popd
  56. echo "*** [$ANDROID_ABI][Finished] Build and install vcpkg dependencies"
  57. if [ -d "$VCPKG_ROOT/installed/arm-neon-android" ]; then
  58. echo "*** [Start] Move arm-neon-android to arm-android"
  59. mv "$VCPKG_ROOT/installed/arm-neon-android" "$VCPKG_ROOT/installed/arm-android"
  60. echo "*** [Finished] Move arm-neon-android to arm-android"
  61. fi
  62. }
  63. if [ ! -z "$ANDROID_ABI" ]; then
  64. build "$ANDROID_ABI"
  65. else
  66. echo "Usage: build-android-deps.sh <ANDROID-ABI>" >&2
  67. exit 1
  68. fi