Warning: A non-numeric value encountered in /home/customer/www/archive.ricston.com/public_html/wp-content/themes/Divi/functions.php on line 5766

The first question that may come to mind after reading this blog post’s title is: “Why would I want to run Android in a VM when I have the emulator?”. For me it boils down to two main reasons:

  1. Android runs significantly faster in a VM compared to the emulator.
  2. VirtualBox offers support for devices such as Bluetooth whereas the emulator doesn’t. This means you can test Android Bluetooth applications in a VM.

There are two ways to make Android run on a VirtualBox VM. The first approach is well known: download the Android x86 fork and follow instructions from the fork’s project website to create a bootable ISO file. From there on, it’s easy to install Android on a VM. The drawback to this approach is that you won’t have the latest Android code. Additionally, changes you make to the fork must be merged with the AOSP (Android Open Source Project) for them to be included in future releases of Android.

The second approach gives you direct access to the latest Android code. However, it’s barely documented due to the fact that previously you couldn’t build ‘out of the box’ an Android VDI (Virtual Disk Image) with the AOSP. To build the Android VDI and install it in your VM, follow these steps:

  1. Get the Android source code from the AOSP site and follow the online instructions to setup the environment.

  2. When you are ready to build the project, execute the following command to set the environment variables for Make: “lunch vbox_x86-eng”.

  3. Run “make installer_vdi” to build the project. Make will build the project and produce a VDI named “installer.vdi” located in “out/target/product/vbox_x86”. This VDI contains Android plus its installer.

  4. Create a Linux VM and add the “installer.vdi” as an extra HD to the VM.

  5. Start the VM and press “F12” during bootup.

  6. Select the HD which represents the “installer.vdi”.

  7. Choose the first option, that is, “Android Install to /dev/sda from /dev/sdb”.

  8. When installation is complete, enter the command “reboot”. After that, you should be able to launch Android from your VM.

One small note, I had several problems trying to compile Android for VirtualBox from my Mac OS X. So probably the best solution is to build Android from Linux.