Skip to content

Instantly share code, notes, and snippets.

@HQarroum
Last active March 17, 2023 00:19
Show Gist options
  • Save HQarroum/012f8c12b9fe587646f52760732fa41d to your computer and use it in GitHub Desktop.
Save HQarroum/012f8c12b9fe587646f52760732fa41d to your computer and use it in GitHub Desktop.
Installs the Android SDK, the platform tools and the emulator on Ubuntu.
#!/bin/bash
set -e
# Installing required packages for the Android SDK
# and the emulator.
sudo apt update -y && \
DEBIAN_FRONTEND=noninteractive sudo apt install -y --no-install-recommends \
unzip \
wget \
openjdk-11-jdk
# Environment variables defining the specific Android SDK
# to install.
export API_LEVEL="${API_LEVEL:-33}"
export IMG_TYPE="${IMG_TYPE:-google_apis}"
export ARCHITECTURE=x86_64
export CMD_LINE_VERSION=9477386_latest
export ANDROID_SDK_ROOT="${ANDROID_SDK_ROOT:-/opt/android}"
export ANDROID_PLATFORM_VERSION="platforms;android-$API_LEVEL"
export PACKAGE_PATH="system-images;android-${API_LEVEL};${IMG_TYPE};${ARCHITECTURE}"
# Importing SDK command-line tools in the path.
export PATH="${PATH}:${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin"
# Downloading and extracting the command-line tools
# in the ANDROID_SDK_ROOT if they don't exist.
if [ ! -d "$ANDROID_SDK_ROOT"/cmdline-tools/ ]; then
wget https://dl.google.com/android/repository/commandlinetools-linux-"${CMD_LINE_VERSION}".zip -P /tmp
mkdir -p "$ANDROID_SDK_ROOT"/cmdline-tools/
unzip -d "$ANDROID_SDK_ROOT"/cmdline-tools/ /tmp/commandlinetools-linux-"${CMD_LINE_VERSION}".zip
mv "$ANDROID_SDK_ROOT"/cmdline-tools/cmdline-tools/ "$ANDROID_SDK_ROOT"/cmdline-tools/tools/
fi
# Installing the Android SDK, platform tools and
# emulator.
echo "Installing Android SDK for API ${API_LEVEL}"
yes | sdkmanager --licenses
sdkmanager --install "$PACKAGE_PATH" "$ANDROID_PLATFORM_VERSION" platform-tools emulator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment