In some cases you might find handy to have an environment for Android apps in your Ubuntu partition, your Virtual Machine or in your VPS. In my case, I have an Android compile environment in a droplet in DigitalOcean, which is very useful to make minor changes and recompile my apps without having direct access to my laptop. However, installing and managing the Android SDK from the console line can be a bit tricky. Here you can find a small guide on how to install the latest Android SDK in Ubuntu (and generally any Linux environment) as well as some tips to keep it light and simple.
1 Download the SDK
First of all, download the latest Open JDK in case you don’t have it installed yet:
sudo apt-get install openjdk-7-jdk
Then navigate to the folder where you want to install the SDK and download it:
Uncompress it and after that remove the compressed downloaded file:
tar xzvf android-sdk_r20-linux.tgz rm android-sdk_r20-linux.tgz
2 Adding the environment variables
Let’s add the Android command to your bash profile. Open your home directory and edit your .bashrc file:
cd vim .bashrc
Add the following lines adapting the paths to the ones you used:
export ANDROID_HOME=/home/android-sdk-linux/ export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
And then reload it by running the command:
Now you can call the Android program from your terminal without being in the android directory, so we can start downloading the latest stuff to work with it.
3 Installing the Android tools and platforms
At this point we can 1) autoupdate and download all the stuff or 2) pick up the necessary stuff to keep it light. I strongly recommend the second option but if you are not confortable enough go with the easy way.
3.1 The easy way
Execute the update command and the update manager will download all the recommended stuff.
android update sdk --no-ui
This will install many old platforms and other files that you’ll probably never use, so when it’s finished you can navigate to your android folder and remove some stuff such as the samples, docs and old platforms:
rm -rf samples rm -rf docs rm -rf platforms/android-10 ...
3.2 The hard way
Pick your required components and install them one by one. You can list all the available elements by running the following command:
android list sdk --all --extended
So to install the latest platform and build tools at the moment I’m writing this post you can execute:
android update sdk -u -a -t "tools" android update sdk -u -a -t "platform-tools" android update sdk -u -a -t "build-tools-23.0.1" android update sdk -u -a -t "android-23"
4 32-bit dependencies on 64-bit systems
Last but not least, some building tools versions have issues when running in 64 bit machines because of the 32-bit dependencies. It is necessary to install the following C libs to get it working:
sudo apt-get install gcc-multilib lib32z1 lib32stdc++6
5 What about Gradle?
If you are using Gradle to compile your projects, be careful when installing it on Ubuntu because the default repositories don’t have the latest version. So run the following commands or you will get the 1.0 version instead of the latest one:
sudo add-apt-repository ppa:cwchien/gradle sudo apt-get update sudo apt-get install gradle
And that’s all. If you have problems getting your console compiling Android, find any mistake in the post or have any suggestions, please feel free to get in touch or leave a comment.