Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mtsahakis/f7893e3b5f0785dd99f304b4822d9b61 to your computer and use it in GitHub Desktop.
Save mtsahakis/f7893e3b5f0785dd99f304b4822d9b61 to your computer and use it in GitHub Desktop.
This document describes how to install Android SDK on a headless Linux server, i.e. a server with no GUI, just a shell. This proved very useful when I had to set up Android builds for Continuous Integration.

Installing Android SDK, NDK and toolset

Search for the download page of Android command line tools. As of this writing, download page is https://developer.android.com/studio/ but this is highly likely to change in the future.

Navigate to the aforementioned download page and search for Command Line Tools link for the specific platform you are targeting. The most likely target platform is Linux.

After locating the link, ssh to your server, preferably as root. Create directory that would ultimately host Android binaries and use wget tool to download Command Line Tools, as per bellow:

mkdir /opt/android
cd /opt/android
wget https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip

** Please replace https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip with the link you previously retrieved.

Unzip the downloaded file and then discard it. If this is a brand new server, you might have to install unzip tool. Bellow are the commands used on an ubuntu server:

apt install unzip
unzip sdk-tools-linux-3859397.zip
rm sdk-tools-linux-3859397.zip

After you unzip sdk-tools, expect a folder aptly named tools under /opt/android directory we created before:

Use sdkmanager tool, found under tools/bin to download core SDK, platform tools (adb, emulator, sqlite3, etc), build tools and Android NDK.

tools/bin/sdkmanager "platform-tools" "platforms;android-27" "platforms;android-26" "build-tools;27.0.3" "ndk-bundle" "lldb;3.1" "cmake;3.6.4111459"

With the command above we were able to download platform-tools, SDK 26, SDK 27, build tools version 27.0.3 and Android NDK, cmake and lldb in one go.

Note that for lldb and cmake, in order to identify and install the latest version, we would need to search for related packages.

A handy way of doing it is displayed bellow:

root@bamboo-apps-01:/opt/android# ./tools/bin/sdkmanager --list | grep -i cmake
  cmake;3.6.4111459                 | 3.6.4111459  | CMake 3.6.4111459               
root@bamboo-apps-01:/opt/android# ./tools/bin/sdkmanager --list | grep -i lldb
  lldb;2.0                          | 2.0.2558144  | LLDB 2.0                        
  lldb;2.1                          | 2.1.2852477  | LLDB 2.1                        
  lldb;2.2                          | 2.2.3271982  | LLDB 2.2                        
  lldb;2.3                          | 2.3.3614996  | LLDB 2.3                        
  lldb;3.0                          | 3.0.4213617  | LLDB 3.0                        
  lldb;3.1                          | 3.1.4508709  | LLDB 3.1

If all the above commands were successful, the following tree structure should be present under /opt/android directory

root@bamboo-apps-01:/opt/android# ls -l
total 36
drwxr-xr-x  3 root root 4096 May  4 11:26 build-tools
drwxr-xr-x  3 root root 4096 May  4 11:54 cmake
drwxr-xr-x  2 root root 4096 May  4 11:19 licenses
drwxr-xr-x  3 root root 4096 May  4 11:53 lldb
drwxr-xr-x 12 root root 4096 May  4 11:49 ndk-bundle
drwxr-xr-x  3 root root 4096 May  4 11:39 patcher
drwxr-xr-x  4 root root 4096 May  4 11:33 platforms
drwxr-xr-x  5 root root 4096 May  4 11:19 platform-tools
drwxr-xr-x  6 root root 4096 May  4 11:16 tools

We would also might need grant write access to /opt/android directory by the application user.

In case a build fails because of write access to /opt/android, simply grant it as per bellow:

chmod +w /opt/android/
@xloem
Copy link

xloem commented Apr 7, 2021

What version of cmdline-tools are you using? Mine doesn't have the ndk components in its repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment