Setup Android development environment on Virtualbox VM

Setup Android development environment on Virtualbox VM

We are going to setup Android development environment with an Android Emulator.

If we install Android Studio (IDE) inside a Virtual Machine, the Android Emulator setup will fail. This is because Android Emulator is itself a Linux OS and cannot run inside another Virtual Machine. The way around this is to create two VMs in Virtual Box, one with development tools and other with Android OS. Then establish networking between the two VMs and connect Android development tools to Android instance in the other VM.

Let’s get started.

Create a Linux VM with Andriod development tools

1- Download preferred Linux OS image in .iso format. Ubuntu, one of the most popular Linux distributions, can be downloaded from here.

2- Create a new Virtual Machine in Virtual Box and set the desired values for RAM, number of CPUs, Secondary Storage etc.

3- Load the download iso file into VM’s optical drive.

4- Start the VM and follow the installation wizard to completion. I have explained steps 2 – 4 in much more detail in another article (see section 1.2).

5- Download Android Studio and unzip it.

6- Start Android Studio by running ./android-studio/bin/studio.sh file. Go through the ‘Android Studio Setup Wizard’. This installs the latest Android SDK, Android SDK Platform-Tools, and Android SDK Build-Tools at~/Android/Sdk folder.

Install Android in a VM

1- Download Android x86 image in .iso format from https://www.android-x86.org/ . They have ported Android to x86 platform. The file I downloaded is android-x86_64-8.1-r1.iso

2- Create a new Virtual Machine in Virtual Box and set the desired values for RAM, number of CPUs, Secondary Storage etc.

3- Change the display option Graphics Controller to VBoxVGA and enable 3D animation for the VM.

Android VM display setting

4- Browse the download Android x86 iso file into VMs optical drive.

5- Start the VM and follow the installation wizard to completion. This also involves setting up the disk partition which can be a bit confusing. Find the details steps with screenshots here.

Establish networking between two VMs

I prefer NAT Network to establish the network between VMs. There are other ways of achieving this, see Virtual Networking Guide for more details.

1- In Virtual Box Preferences, create a new NAT Network. Note that this is in Virtual Box preferences, not in the settings of any VM.

2- Make sure both the VMs are turned off.

3- Change network of both VMs to NAT Network and select the name you just gave to new NAT Network.

Android VM Network Setting
Linux development VM Network Setting

Connect Android SDK with Android instance running in another VM

1- Start both VMs.

2- Find the IP Address of Android VM. You do that by searching for IP Address in settings.

3- Connect to Android from Android SDK using adb. Use the IP Address of Android VM and 5555 as port number.

~$ cd Android/Sdk/platform-tools/
~/Android/Sdk/platform-tools$ ./adb connect 10.0.2.4:5555

daemon not running; starting now at tcp:5037
daemon started successfully
connected to 10.0.2.4:5555

One Reply to “Setup Android development environment on Virtualbox VM”

Leave a Reply

Your email address will not be published.