Preparing your Android Environment for development — Android Tutorials pt. 1

About 5 years ago, I created an Android development series in my personal blog. In technology, 5 years is like an era, so for 2017, I intend to update and possibly expand them. If you want, you can find the Portuguese version of this tutorials there in my blog.

Setting up Windows

The first step is to setup your Windows, is to download the JDK (Java Development Kit). It will help us with all the needed tools for Java development, that will be used for Android apps as well. You can download it from Oracle. The installation will show a wizard, so no surprises by now.

The next step is to download Android Studio. Prefer the bundle option, as it already contains most of the needed tools and an emulator. Just follow the wizard and keep going.

The last step is to export the environment variables JAVA_HOME and ANDROID_HOME, so we can build from command line when needed. First, export ANDROID_HOME. If you didn’t changed the installation path, use this value:

%LOCALAPPDATA%\Android\sdk

Then, export JAVA_HOME. If you changed the installation path, use your own. If not, the value should be:

%ProgramFiles%\Java\jdk1.8.0_111

And, at last, let’s add the binaries to the system Path, so we can run them in any folder. Add this to your Path:

%ANDROID_HOME%\tools
%ANDROID_HOME%\platform-tools
%JAVA_HOME%\bin

To assert that all the setup went well, check if the commands adb and javac are available in your console.

During the Android Studio installation, the HAXM tools will be installed as well (in case your processor being compatible with it). HAXM allows your machine to run the Android emulator with excellent performance. Another good option for emulators is Genymotion, but for most cases, the default emulator should fit.

And, at last, it’s optional but highly recommended to install Git.

Setting up OSX

In OSX (Mac), the installations is very similar to Windows. First of all, download the JDK from Oracle website. The installation should occur fine, just follow the installation wizard.

Then, download Android Studio. The dmg file installation is very similar to any other installation of an OSX program, just drag and drop and you’re ok. When you execute it for the first time, it will download the needed SDKs and HAXM for better emulation.

The last step is to setup the environment variables, used for command line builds and tooling. Since you didn’t changed the default paths when installing, add the following to your ~/.bash_profile file (if the file doesn’t exist, create it).

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$JAVA_HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

And, at last, it’s optional but highly recommended to install Git (prefer to install it through Homebrew, for most recent versions).

Setting up Linux

On Linux, as we have default package managers, the process itself is very easy. If you’re an Ubuntu / Linux Mint user, just run on your terminal:

sudo apt-get install lib32z1 lib32ncurses5 lib32stdc++6 openjdk-8-jdk qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils

If you’re using Fedora, then run:

sudo dnf install glibc.i686 glibc-devel.i686 libstdc++.i686 zlib-devel.i686 ncurses-devel.i686 libX11-devel.i686 libXrender.i686 libXrandr.i686 java-1.8.0-openjdk-devel qemu-kvm

Other distributions can have different names for the packages, but with a quick search they can be found. Linux doesn’t use HAXM for emulation acceleration — for this porpouse, we have KVM, a virtualization engine that relies on Linux Kernel (if your processor supports it).

The next step is to download Android Studio. For Linux, the file has the .tar.gz extension, and should be placed in a convenient folder (e.g. ~/Android). Then, execute the studio.sh file inside bin folder. When first executed, it will download the necessary SDK files. For easier launching, and better integration with your graphic environment, select the option Configure, then Create Desktop Entry, so you can access Android Studio from your applications menu (in Unity, Gnome, KDE and so).

The last step is to exporte the ANDROID_HOME enviroment variable, and put all the tools on Path. Open the ~/.bashrc file, or ~/.zshrc (if you use z-shell), and add the following lines. If you changed the default SDK location, change with your config:

export ANDROID_HOME="$HOME/Android/Sdk"
export PATH="$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools"

And, at last, it’s optional but highly recommended to install Git (use the system package manager).

Show your support

Clapping shows how much you appreciated Rafael Toledo’s story.