Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save Ashok-Varma/6b5864c1e444a3f1b61158254a43c4bc to your computer and use it in GitHub Desktop.
Save Ashok-Varma/6b5864c1e444a3f1b61158254a43c4bc to your computer and use it in GitHub Desktop.
Install Android SDK tools in linux. Can be used for custom CI (Continuous Integration)

This post shows how to install android sdk tools without Android Studio. We might need to do in many cases like setting up an CI machine ..etc

We need java, android(tools, build tools), gradle.

Table of contents

  1. Setup server
    1. System Requirements
    2. Install java Jdk
    3. Install sdk tools
    4. Build-tools installation
    5. Path Export
    6. Extras
    7. Install Gradle
  2. Test
  3. Update machine
  4. Trouble Shoot

Setup server

System Requirements

  1. 64-bit distribution capable of running 32-bit applications
  2. GNU C Library (glibc) 2.19 or later
  3. 3 GB RAM minimum, 8 GB RAM recommended (For massive projects min 8GB is required for decent fast builds)
  4. 2 GB of available disk space minimum

Install java Jdk

  1. check if Jdk exists
javac -version
  1. if none installed, install java JDK (not JRE)
sudo apt-get install openjdk-8-jdk 

Install sdk tools

  1. Go to https://developer.android.com/studio/index.html scroll till the end and get url of latest linux command tools.

Current version(https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip)

  1. create some folder and cd there and get the tools
wget https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip

in my case i created var/dev/android and download

  1. Unzip the file. if unzip is not installed, install it
apt install unzip
unzip fileName -d dirPathWhereTo
# fileName => downloaded file name
# dirPathWhereTo => directory where to unzip
  1. Install platform tools and others. cd to tools in unzipped folder and install all sdk packages
./android update sdk --no-ui

step 4 takes time and this cmd has no progress ui representation, so please be patient

now both SDK and platform_tools are installed

Build-tools installation

  1. To get the list of files, cd to tools/bin and execute
./sdkmanager --list
  1. now install the build tools that you need
# change version based on your requirements
./sdkmanager "build-tools;26.0.1"
  1. if you need to install multiple tools from sdkManager use coma separated string
./sdkmanager "build-tools;26.0.1,platforms;android-25"

Path Export

  1. Edit etc/profile. So on every Login these get executed.
nano /etc/profile
  1. add these commands.
# change it according to your path and version
export PATH=${PATH}:var/dev/android/sdk/platform-tools:var/dev/android/sdk/tools:var/dev/android/sdk/build-tools/26.0.1/
export ANDROID_HOME=var/dev/android/sdk/
  1. save it
  2. logout (exit ssh) and Login (open a new shell), then type "echo $PATH", "echo $ANDROID_HOME" to verify
echo $PATH
echo $ANDROID_HOME

Extras

  1. If you get "~/.android/repositories.cfg file not found" error too often. Then execute this command to create that file,this file is of no use but just to avoid a warning which pops too often.
touch ~/.android/repositories.cfg

Install Gradle

  1. find the gradle version you need
  2. from android plugin version get the gradle version => (https://developer.android.com/studio/releases/gradle-plugin.html)
  3. or can also be found from gradle-wrapper.properties
  4. get gradle link based on version you need from https://gradle.org/releases/
wget https://services.gradle.org/distributions/gradle-4.1-all.zip
  1. make new directory
mkdir /opt/gradle
  1. unzip gradle to that location (/opt/gradle)
  2. To /etc/profile file. add the following command (similar to Path Export step-1,2)
export GRADLE_HOME="/opt/gradle/gradle-4.1/bin
  1. Add the gradle to path as well => just add $GRADLE_HOME for the line which we added earlier in Path Export step-2.
# so now the file will have these lines 
export ANDROID_HOME=var/dev/android/sdk/
export GRADLE_HOME="/opt/gradle/gradle-4.1/bin
export PATH=${PATH}:var/dev/android/sdk/platform-tools:var/dev/android/sdk/tools:var/dev/android/sdk/build-tools/26.0.1/:$GRADLE_HOME
  1. logout and login again => verify gradle.
gradle -v

Test

# Check gradle version - To Verify gradle path
gradle -v

# Verify jre path
java -version

# Verify jdk path
javac -version

# Verify tools path
android list device

# Verify platform-tools path
adb devices

Update machine

  1. Update all tools and platform-tools
android update sdk --no-ui
  1. Get new build tools
sdkmanager "build-tools;required_version"
  1. Download and unzip gradle
  2. Edit /etc/profile based on new versions. (similar to Path Export step-1,2)
  3. Logout and Login and perform test

Trouble Shoot

  1. Check if machine has enough Power (Ram/CPU's).
Common errors due to Less Ram
    1. Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
    2. OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000089b00000, 524288, 0) failed; error='Cannot allocate memory' (errno=12)
# To check Ram usage
free -m

# More detail Ram/CPU Usage
top

# Check no of CPU's
lscpu | egrep '^Thread|^Core|^Socket|^CPU\('
  1. Check if machine has internet access
ping 8.8.8.8
  1. Check if android build tools version in machine match with your project. If not update
sdkmanager "build-tools;required_version"
  1. Check if machine has all required environmental variables.
printenv | grep environmental_variable_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment