Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install Android SDK on headless Ubuntu linux machine via command line, so that you can compile open source Android apps.
adduser runner
#basic stuff
apt-get install curl
apt-get install screen
apt-get install xz-utils
apt-get install git
apt-get install ping
# Thanks to
# Execute this script in your home directory. Lines 17 and 21 will prompt you for a y/n
# Install Open JDK 8
add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install wget
apt-get install openjdk-8-jdk-headless
apt-get install -y unzip make # NDK stuff
# Add some swap space, useful if you've got less than 2G of RAM
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
# Make sure you can execute 32 bit executables if this is 64 bit machine, otherwise skip this
dpkg --add-architecture i386
apt-get update
apt-get install -y libc6:i386 libstdc++6:i386 zlib1g:i386
#### as user
exec su - runner - << eof
# Get SDK tools (link from
tar xf android-sdk*-linux.tgz
# Get NDK (
unzip android-ndk*.zip
# Let it update itself and install some stuff
cd android-sdk-linux/tools
echo y | ./android update sdk --no-ui
# Download every build-tools version that has ever existed
# This will save you time! Thank me later for this
echo y | ./android update sdk --all --no-ui --filter $(seq -s, 27)
# If you need additional packages for your app, check available packages with:
# ./android list sdk --all
# install certain packages with:
# ./android update sdk --no-ui --all --filter 1,2,3,<...>,N
# where N is the number of the package in the list (see previous command)
# Add the directory containing executables in PATH so that they can be found
touch ~/.bashrc
echo 'export ANDROID_HOME=/home/runner/android-sdk-linux' >> ~/.bashrc
echo 'export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools' >> ~/.bashrc
source ~/.bashrc
# Optionally run build system as daemon (speeds up build process)
mkdir -p ~/.gradle
echo 'org.gradle.daemon=true' >> ~/.gradle/
# See here:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment