# Android-x86: Extended emulator configuration

Requirements

  • Any linux distro (I prefer Arch Linux)
  • Android x86 project sources
  • 4.7 > GCC >= 4.4
  • Python 2.7
  • Perl 5
  • Google repo tool
  • Virtualbox VM
  • Android SDK Tools
  • Eclipse (optional)

Goal

Google Android Emulator works on top of the x86 processor architecture, that’s why the efficiency is quite low. Luckily, there exists a project called Android-x86 which uses kernel compiled to x86 architecture, so you can use it as a native system (with full x86 instruction set).

We’re going to create our own build of android-x86 with Android 2.3.3 and run it on Virtualbox machine with some features:

  • We’ll use LiveCD (I prefer to use default android system – not installed – for tests)
  • We’ll use two ethernet devices (first for debugging, second for NAT)
  • We’ll set some non-default resolutions in syslinux loader

Get the sources

# Connect with the device

mkdir android-x86
cd android-x86
repo init -u http://git.android-x86.org/manifest -b gingerbread-x86
repo sync

Prepare environment

During compilation some errors occured because of wrong environment setup. First of all, if you use i.e gcc-4.6.6 then add it to your $PATH

ln -s /usr/bin/gcc-4.6.6 ~/bin/gcc
export PATH=~/bin/:$PATH
which gcc

Or simply create symlink

rm /usr/bin/gcc
ln -s /usr/bin/gcc-4.6.6 /usr/bin/gcc

And do the same for python if you’re not using 2.7 version. To be 100% sure that you compiler version is correct perform

export CXX=/usr/bin/gcc-4.6.6

Compile (before changes)

Eventually! Let’s compile:

make -j4 iso_img TARGET_PRODUCT=vm

On ubuntu everything goes fine but unfortunately on Arch Linux I got some issues, so:

# If errors occured install (64bit system with multilib repo)
pacman -S lib32-readline lib32-ncurses

# If error occured in "dalvik/vm/native/dalvik_system_Zygote.c" add:
#include "sys/resource.h"

Now you should have vm.iso file in "android-x86/out/target/product/vm/". If not, look for errors and try again.

Modify the sources

Now it’s time for some changes:

# Setup isolinux (We'd like to run android emulator in specified resolution)
nano bootable/newinstaller/boot/isolinux/isolinux.cfg

# Add two boot options (first for standard android phone, second for tablet device)
label liveh
        menu label Live CD - ^Run Android-x86 without installation (LDPI)
        kernel /kernel
        append initrd=/initrd.img CMDLINE quiet SRC= DATA= DPI=120 UVESA_MODE=320x480

label livem
        menu label Live CD - ^Run Android-x86 without installation (MDPI)
        kernel /kernel
        append initrd=/initrd.img CMDLINE quiet SRC= DATA= DPI=160 UVESA_MODE=800x600

Let’s add one extra ethernet interface eth1. In our configuration "eth0" is used
to connect via adb and "eth1" is NAT interface. So it’s very convinient way to
assign network address during boot i.e "192.168.56.101".

You could ask "Why do we need two eth’s, one isn’t enough?" Good question! We
could use one bridged adapter that solves our problem. But when we have no internet connection, it’s quite impossible to use adb (because of no address, I’m not 100% sure about that, but it seems to work that way).

# Enough talking! Let's do it:
nano bootable/newinstaller/initrd/scripts/0-auto-detect

# modify function find_network_dev_name()
"if [ "$netdev" != "lo" -a "$netdev" != "wmaster0" ]; then"
to
if [ "$netdev" != "lo" -a "$netdev" != "eth0" -a "$netdev" != "wmaster0" ]; then

# Now let's add new service to init.rc, add line before "class_start default"
setprop net.eth0.setUp 1

# At the end add
on property:net.eth0.setUp=1
   start up_eth0

service up_eth0 /system/bin/ifconfig eth0 192.168.56.101
    disabled
    oneshot

# Compile again (Step 5.)
make -j4 iso_img TARGET_PRODUCT=vm

Create virtual machine

Install VirtualBox machine (wiki):

pacman -S virtualbox virtualbox-host-modules virtualbox-guest-utils virtualbox-guest-modules

# add modules
modprobe -a vboxdrv vboxnetadp vboxnetflt

Your new virtual machine should be like:

  • Operating System: Other Linux
  • Network Adapter 1: PCnet-Fast ||| (Host Only)
  • Network Adapter 1: PCnet-Fast ||| (NAT)
  • Storage: IDE Primary Master[CD/DVD] – vm.iso

Now edit your .vbox file:

```
# Add lines
<ExtraDataItem name="CustomVideoMode1" value="320x480x16"/>
<ExtraDataItem name="CustomVideoMode2" value="800x600x16"/>

# Or by
VBoxManage setextradata "YourVMName" "CustomVideoMode1" "320x480x16"
VBoxManage setextradata "YourVMName" "CustomVideoMode2" "800x600x16"
```

And the very last step is to connect via adb (or eclipse with adt) to machine:

adb connect 192.168.56.101
adb shell

Demo

Sources: