Explains all the steps required to install Android SDK Tools on Ubuntu 18.04 LTS without using Android Studio.

How To Install Android SDK Tools On Ubuntu 18.04
How To Install Android SDK Tools On Ubuntu 18.04
September 08, 2019

In this post, we will discuss all the steps required to install Android SDK Tools on the popular Linux distribution i.e. Ubuntu 18.04 with Java 8. This tutorial also assumes that the SDK manager works out of the box with JDK 8 or lower since JDK 9, 10, 11, and 12 have reported compatibility issues with Android SDK. You might be required to fall back to older JDK in case you face any compatibility issues. There are solutions suggested by the community to work with JDK 9 and 10 as shown at the end of this post. As of writing this tutorial, Android SDK won't work with JDK 11 and 12 due to the removal of modules required by it.

This post is useful for the developers using Android SDK Tools with other IDEs without installing Android Studio for the use cases including hybrid app development using Ionic. It also assumes that a valid JAVA_HOME environment variable exists pointing to the installation directory of Java. You may follow the Java installation tutorials written by us including How To Install Java 8 On Ubuntu, How To Install Java 10 On Ubuntu.

In case you are interested in developing Android applications using Android Studio, you can also follow the other tutorials written by us including How To Install Android SDK Tools On Windows, How To Install Android Studio On Windows, and How To Install Android Studio On Ubuntu 18.04.

Notes: You may follow the installation instructions from How To Install Java 8 On Ubuntu to install Java 8. You may also be required to execute below-mentioned command in case you have set the options previously for Java 9 or Java 10.

# The saviour command
unset JAVA_OPTS

Download SDK Tools

Open the download tab of Android Studio and scroll down to Command line tools only section. This section shows various options to download the SDK tools as shown in Fig 1.

Android SDK Download

Fig 1

Click on the Download Link as highlighted in Fig 1. It will ask to accept the Terms and Conditions as shown in Fig 2.

Android SDK License Agreement

Fig 2

Go through the details, agree on the terms and conditions and click on the Download Button to start the download.

Install SDK Tools

Create a directory having name set to android-sdk and extract the content of the downloaded SDK Tools zip to this directory. Make sure that the extracted content is available within the android-sdk directory created by us.

Download and Install Platform Tools

Follow the same steps similar to Android SDK Tools as shown in Fig 3, Fig 4, and Fig 5 to install Android Platform Tools using the download link.

Android Platform Tools Download

Fig 3

Android Platform Tools Terms

Fig 4

Android SDK and Platform Tools

Fig 5

Make sure that the platform-tools content is available within the directory platform-tools.

Configure Environment Variable

In this step, we will configure the environment variable to use the SDK tools installed by us. There are two ways to do it. In the first approach, we can update the .bashrc file of the user account. Another approach is to update /etc/profile file which works for all the accounts.

Approach A

Update .bashrc file of the user account.

# Update Bash
sudo nano ~/.bashrc

# Add at the end of the .bashrc file
export ANDROID_HOME=/drivea/java/android/android-sdk
export PATH=/drivea/java/android/android-sdk/platform-tools:/drivea/java/android/android-sdk/tools:/drivea/java/android/android-sdk/tools/bin:${PATH}
# sdkmanager fix for java 9 and 10
#export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'

# Save .bashrc

# Reload Bash
source ~/.bashrc

Notes: Replace the android sdk path based on your installation directory.

Approach B

Update /etc/profile file.

>sudo nano /etc/profile

Scroll down by pressing Page Down button and add at the end of this file:

# OpenJDK 12
#JAVA_HOME=/usr/java/jdk-12.0.2
# Java 8
JAVA_HOME=/usr/java/jdk1.8.0_221
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

# Android SDK Tools and Platform Tools
export ANDROID_HOME=/drivea/java/android/android-sdk
export ANDROID_SDK_ROOT=/drivea/java/android/android-sdk
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

# sdkmanager fix for java 9 and 10
#export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'

# optional to add tools to system path to run emulator and other commands
# The android command available within this path is officially deprecated
export PATH=$PATH:$ANDROID_HOME/tools

Make sure that you provide the correct path to the android-sdk directory.

Now press Ctrl + O and press Enter to write our change. Press Ctrl + X to exit the nano editor. The nano editor should look like the one shown in Fig. 6.

Android SDK Environment Variable

Fig 6

Now test the Android SDK installed by us using the environment variables configured by us.

# Check adb version
adb --version

# It must show the installed adb version
Android Debug Bridge version 1.0.41
Version 29.0.2-5738569
Installed as /drivea/java/android/android-sdk/platform-tools/adb


# Check sdkmanager version
sdkmanager --version

# It must shown installed sdkmanager version
26.1.1

Using the SDK Manager

List - We can list the installed and available packages and images using list command as shown below.

// List all the installed and available platforms, system images and other resources 
sdkmanager --list

// Output should look like
Installed packages:=====================] 100% Computing updates...
Path | Version | Description | Location
------- | ------- | ------- | -------
platform-tools | 29.0.2 | Android SDK Platform-Tools 29.0.2 | platform-tools/
tools | 26.1.1 | Android SDK Tools 26.1.1 | tools/

Available Packages:
...
...

// We can see that it shows the tools and platform-tools installed by us

Install Platform - Use the below-mentioned command to install the Android 10 (API level 29) using the SDK manager.

# Start downloading the most recent package
sdkmanager "platforms;android-29"

It will ask to accept the terms and conditions. Enter y and hit Enter Key to accept the terms and conditions. This command creates the directory platforms within android-sdk and installs the package android-29 having all the required files to run the emulator for Android 10.

If we again check the installed packages, the list command shows the installed options as shown below.

sdkmanager --list
Installed packages:=====================] 100% Computing updates...
Path | Version | Description | Location
------- | ------- | ------- | -------
platform-tools | 29.0.2 | Android SDK Platform-Tools 29.0.2 | platform-tools/
platforms;android-29 | 3 | Android SDK Platform 29 | platforms/android-29/
tools | 26.1.1 | Android SDK Tools 26.1.1 | tools/

Available Packages:
...
...

Update SDK Manager - Update the SDK manager using the below-mentioned command.

sdkmanager --update

Add System Image - We can add system image from available images shown by list command using the SDK manager as shown below. We are adding the most recent default 64-bit system image.

// Install default system image for platform android-29
sdkmanager "system-images;android-29;default;x86_64"

Accept the License Agreement to complete the download.

There are several projects which need Google Play Services. We need system images specific to Google Play Services as shown below.

// Install Google Play Services system image
sdkmanager "system-images;android-29;google_apis_playstore;x86_64"

Install Emulator - We need to install the emulator before creating the AVD using SDK Manager.

// Install Emulator
sdkmanager --channel=3 emulator

Install Build Tools - Install the most recent build tool listed by the list command.

// Install Build Tools
sdkmanager "<build tools version>"

// Example
sdkmanager "build-tools;29.0.2"

Using the Emulator and AVD Manager

Create Android Emulator - Create the emulator using the system image downloaded in the previous step as shown below. Replace <emulator name> with actual name.

// Create the emulator using default system image
avdmanager create avd -n <emulator name> -k "system-images;android-29;default;x86_64" -g "default"

// Create emulator using Google Play Services system image
avdmanager create avd -n <emulator name> -k "system-images;android-29;google_apis_playstore;x86_64"

The above commands ask a bunch of question to configure the AVD if we choose the custom hardware profile option. We have excluded the details of these options from this tutorial since these configuration details depend on the actual needs. After completing all the configurations, it creates the AVD using the name provided by us while configuring it.

List Android Emulators - Now go to the tools directory(only required in case you have ommited to add tools path to PATH while configuring environment variables) on the command line and check the installed platform as shown below.

# List the available emulators
cd /drivea/java/android/android-sdk/tools
./emulator -list-avd

# OR - In case tools is added to system path -> $ANDROID_HOME/tools
emulator -list-avd

It will list all the AVDs installed by us.

Run Emulator - We can run the emulator created by us as shown below.

// Run Emulator
sudo ./emulator -avd <emulator name>

The above command might show an error specific to the qt library. We can execute the emulator from the Android SDK Tools directory in such case.

The emulator will take some time to completely launch the AVD. The final results should look similar to the one shown in Fig 7.

Android SDK Emulator

Fig 7

Delete Emulator - We can also delete an existing emulator as shown below.

// Delete Emulator
avdmanager delete avd -n <emulator name>

Working with JDK 9 and 10

Use the below-mentioned command for JDK 9 and 10 on Linux and Windows.

// Linux/Mac
export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'

// Windows
set JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'

Modifying the SDK manager script is another option as shown below.

// Replace this
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME"'

// With
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'

We need to download additional jars(JAXB, JAF) and modify the SDK manager script - sdkmanager.bat for Java 11 as shown below.

set CLASSPATH=jaxb-core.jar;jaxb-impl.jar;jaxb-api.jar;activation.jar

Write a Comment

Click on the captcha image to get new code.
Discussion Forum by DISQUS