install-ubuntu-android-tools.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. # This script must be run as root
  8. if [[ $EUID -ne 0 ]]
  9. then
  10. echo "This script must be run as root (sudo)"
  11. exit 1
  12. fi
  13. #
  14. # Make sure we are installing on a supported ubuntu distro
  15. #
  16. lsb_release -c >/dev/null 2>&1
  17. if [ $? -ne 0 ]
  18. then
  19. echo This script is only supported on Ubuntu Distros
  20. exit 1
  21. fi
  22. #
  23. # Install the necessary tools to download, install, and run the android tools
  24. #
  25. apt install -y openjdk-11-jdk unzip wget
  26. mkdir /opt/android-sdk-linux
  27. wget -q https://dl.google.com/android/repository/commandlinetools-linux-6609375_latest.zip -O /tmp/commandlinetools-linux.zip
  28. if [ $? -ne 0 ]
  29. then
  30. echo "Error downloading the Android command line tools"
  31. exit 1
  32. fi
  33. unzip /tmp/commandlinetools-linux.zip -d /opt/android-sdk-linux/cmdline-tools
  34. if [ $? -ne 0 ]
  35. then
  36. echo "Error extracting the Android command line tools to /opt/android-sdk-linux/cmdline-tools"
  37. exit 1
  38. fi
  39. rm -f /tmp/commandlinetools-linux.zip
  40. for i in "cmdline-tools;latest" "build-tools;30.0.2" "platform-tools" "platforms;android-24" "ndk;25.2.9519653"
  41. do
  42. echo "Installing official $i"
  43. yes | /opt/android-sdk-linux/cmdline-tools/tools/bin/sdkmanager --install "$i"
  44. if [ $? -ne 0 ]
  45. then
  46. echo "Error installing '$i'"
  47. exit 1
  48. fi
  49. done
  50. # Add the path and necessary environment variable to build android based on NDK 25.2.9519653
  51. echo 'export PATH="$PATH:/opt/android-sdk-linux/cmdline-tools/latest/bin/"' > /etc/profile.d/android-env.sh
  52. echo "export LY_NDK_DIR=/opt/android-sdk-linux/ndk/25.2.9519653" >> /etc/profile.d/android-env.sh
  53. chmod a+x /etc/profile.d/android-env.sh