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.
- 64-bit distribution capable of running 32-bit applications
- GNU C Library (glibc) 2.19 or later
- 3 GB RAM minimum, 8 GB RAM recommended (For massive projects min 8GB is required for decent fast builds)
- 2 GB of available disk space minimum
- check if Jdk exists
javac -version
- if none installed, install java JDK (not JRE)
sudo apt-get install openjdk-8-jdk
- 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)
- 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
- 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
- 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
- To get the list of files, cd to tools/bin and execute
./sdkmanager --list
- now install the build tools that you need
# change version based on your requirements
./sdkmanager "build-tools;26.0.1"
- if you need to install multiple tools from sdkManager use coma separated string
./sdkmanager "build-tools;26.0.1,platforms;android-25"
- Edit etc/profile. So on every Login these get executed.
nano /etc/profile
- 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/
- save it
- logout (exit ssh) and Login (open a new shell), then type "echo $PATH", "echo $ANDROID_HOME" to verify
echo $PATH
echo $ANDROID_HOME
- 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
- find the gradle version you need
- from android plugin version get the gradle version => (https://developer.android.com/studio/releases/gradle-plugin.html)
- or can also be found from gradle-wrapper.properties
- get gradle link based on version you need from https://gradle.org/releases/
wget https://services.gradle.org/distributions/gradle-4.1-all.zip
- make new directory
mkdir /opt/gradle
- unzip gradle to that location (/opt/gradle)
- To /etc/profile file. add the following command (similar to Path Export step-1,2)
export GRADLE_HOME="/opt/gradle/gradle-4.1/bin
- 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
- logout and login again => verify gradle.
gradle -v
# 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 all tools and platform-tools
android update sdk --no-ui
- Get new build tools
sdkmanager "build-tools;required_version"
- Download and unzip gradle
- Edit /etc/profile based on new versions. (similar to Path Export step-1,2)
- Logout and Login and perform test
- 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\('
- Check if machine has internet access
ping 8.8.8.8
- Check if android build tools version in machine match with your project. If not update
sdkmanager "build-tools;required_version"
- Check if machine has all required environmental variables.
printenv | grep environmental_variable_name
https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
This is the last download link. Because sdk-tools is deprecated.