John Jerald De Chavez

Setup Android SDK without Android Studio on Linux

This guide provides instructions for setting up Android SDK.

Pre-requisite

Install Java with SDKMan

First thing todo we need to install sdkman on our machine. You can follow this guide to install sdkman.

After installing sdkman, we need to install java by sdk install java command.

Downloading: java 21.0.1-tem

In progress...

######################################################################## 100.0%

Installing: java 21.0.1-tem
Done installing!

Now you will be prompted if you want this version to be set as default.

Do you want java 21.0.1-tem to be set as default? (Y/n):

Answering yes (or hitting enter) will ensure that all subsequent shells opened will have this version of the SDK in use by default.

Great we have installed java on our machine.

Setup Android SDK

Before we download commandline-tools, we need to create a "Android" folder on our root directory.

mkdir ~/Android

Create a folder Sdk inside of Android folder.

mkdir ~/Android/Sdk

We need to download commandline-tools from Android Developer and download Linux platform.

Go to the path to our downloaded commandlinetools-linux-*.zip file and unzip to get cmdline-tools folder.

unzip commandlinetools-linux-*.zip

After unzipping the file, cmdline-tools folder must contains:

drwxr-xr-x  2 jerald jerald   4096 Ene  4 16:06 bin
drwxr-xr-x 17 jerald jerald   4096 Ene  4 14:21 lib
-rwxr-xr-x  1 jerald jerald 120492 Ene  1  2010 NOTICE.txt
-rwxr-xr-x  1 jerald jerald     86 Ene  1  2010 source.properties

Redirect to the cmdline-tools folder and make a folder name latest and move everything on cmdline-tools into latest folder. So cmdline-tools folder should look like this:

drwxr-xr-x 3 jerald jerald 4096 Ene  4 14:48 .
drwxr-xr-x 4 jerald jerald 4096 Ene  4 16:12 ..
drwxr-xr-x 4 jerald jerald 4096 Ene  4 14:48 latest

Redirect on ./latest/bin folder and execute sdkmanager with a command of ./sdkmanager --list

The result should look like this:

Available Packages:
  Path                                                                                     | Version       | Description
  -------                                                                                  | -------       | -------
  add-ons;addon-google_apis-google-15                                                      | 3             | Google APIs
  add-ons;addon-google_apis-google-16                                                      | 4             | Google APIs
  add-ons;addon-google_apis-google-17                                                      | 4             | Google APIs
  add-ons;addon-google_apis-google-18                                                      | 4             | Google APIs
  add-ons;addon-google_apis-google-19                                                      | 20            | Google APIs
  --others--

Here we can install the packages that we needed; Run the command ./sdkmanager "platform-tools" "build-tools;34.0.0" to install platform-tools and Android SDK packages. Android folder should contains:

[jerald@cassini Android]$ ls
build-tools  cmdline-tools  emulator  licenses  platform-tools  Sdk  tools

Move build-tools, emulator, licences, platform-tools, tools, and .temp folders to Sdk folder.

Finally we need to update our .bashrc to register the path of our sdk.

# android sdk, command-line-tools
export ANDROID_HOME="$HOME/Android/Sdk"
export PATH="$HOME/Android/platform-tools:$PATH"

Now you already setup Android SDK without Android Studio. I hope this guide help you to setup. You can check some common issue section that I also encountered during the experiment.

Common Issues

Currently, I'm working on React-Native apps and I encounter something like this:

> react-native run-android

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1376 file(s) to forward-jetify. Using 4 workers...
info JS server already running.
/bin/sh: line 1: /home/jerald/Android/Sdk:/bin/platform-tools/adb: No such file or directory

Solution: Make sure PATH of platform-tools is exist.

Bonus: Guide working on Physical Device

To connect your physical device on your backend server we need to know the device name by adb devices command.

> adb devices
List of devices attached
1c273304        device

After knowing the device name we can run adb -s 1c273304 reverse tcp:3000 tcp:3000 command (Note the 3000 is your development server port).

References