Skip to content

Instantly share code, notes, and snippets.

@aitsuki
Last active August 2, 2024 09:19
Show Gist options
  • Save aitsuki/1af01859d88745aab1f5c4662931099d to your computer and use it in GitHub Desktop.
Save aitsuki/1af01859d88745aab1f5c4662931099d to your computer and use it in GitHub Desktop.
Install android sdkmanager on centos with root user.
#!/usr/bin/env sh
# install openjdk
rpm --import https://yum.corretto.aws/corretto.key
curl -L -o /etc/yum.repos.d/corretto.repo https://yum.corretto.aws/corretto.repo
echo ""
echo "Please choose the Java version: (Gradle 8.0 requires Java 17)"
echo "1: java-11-openjdk-devel"
echo "2: java-17-openjdk-devel"
read -p "Please enter: " choice
case $choice in
1)
yum install -y java-11-amazon-corretto-devel || { echo "Java 11 installation failed"; exit 1; } ;;
2)
yum install -y java-17-amazon-corretto-devel || { echo "Java 17 installation failed"; exit 1; } ;;
*)
echo "Invalid choice!"
exit 1 ;;
esac
# install git
yum -y install git || { echo "Git installation failed"; exit 1; }
git config --global credential.helper store
# install sdkmanager
latest_tools_url="https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip"
wget "$latest_tools_url" -O latest.zip
mkdir -p android-sdk/latest
unzip -d android-sdk latest.zip
mv android-sdk/cmdline-tools/* android-sdk/latest
mv android-sdk/latest android-sdk/cmdline-tools
# update environment variables
echo '
export PATH=$PATH:/root/android-sdk/cmdline-tools/latest/bin
export ANDROID_HOME=/root/android-sdk' >> /root/.bashrc
source /root/.bashrc
# accept sdkmanager license
yes | sdkmanager --licenses || { echo "SDK manager license acceptance failed"; exit 1; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment