This blog is a collection of hands-on notes on building Android ICS 4 virtualbox installer for x86 from official Google x86 virtualbox target vbox-x86-eng (included in ICS 4.0 source) and using a Linux 2.6 kernel provided by Intel to add specific feature for virtualbox and how to use installer.vdi to install Android ICS 4.0 into Virtualbox.
In addition to Google AVD emulator supported by Intel Hardware Accelerated Execution Manager (HAXM) technology (already available Here), Android for x86 Virtualbox is completely running x86 codes and provides another fast and high performance tool for developer and partner for quick app development and testing. Booting an Android ICS 4 in virtualbox takes about 20 seconds, same process on an ARM-based ICS 4 AVD emulator in Eclipse takes 65 seconds. Speed, performance, and user experience are all counted for the popularity of virtualbox among Android developers, especially for x86 platform. It takes time for x86 based Android tablet and phone to be easily available on the market. Develop apps on AVD and virtual platform continue to be a top option for Android for X86 developers.
Why Google provides Virtualbox build Target for ICS 4?
If you have been using Google’s latest ICS source repo, you probably have noticed that Google provided an x86 version of Virtualbox target vbox_x86-eng. When you key in the lunch command before start your build, the first three targets that Google provide for ICS 4.0.1 are:
With vbox_x86-eng (#3) target, developer and system builder can compile and make android_disk.vdi and android installer.vdi which can be used to run Android ICS 4 in virtualbox for app development and system integration on Windows, Linux and IOS platform .
Downloading the Source Tree and Installing Repo
Read Things I Wish I Knew Before I Built My First Android-x86 from Google Source Supported by Intelto set up your app development platform and get ready for your Android build.
To install, initialize, and configure Repo, follow these steps (More detail on Android source site) :
$ mkdir ~/bin
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ mkdir ANDROID_TOP_PATH
$ cd ANDROID_TOP_PATH
To get a list of available branches, (from your android repo checkout root), use this command:
$ git --git-dir .repo/manifests/.git/ branch -a
Google ICS 4.x are listed below:
Run repo init to bring down the latest version of Repo with all its most recent bug fixes. I check out android-4.0.1_r1 at this hands-on:
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
To use the Gerrit code-review tool, you will need an email address that is connected with a registered Google account. Make sure this is a live address at which you can receive messages. The Kernel version and Build number will be assigned to your build, and information will be displayed in Android/settings/about phone/ page.
A successful initialization will end with a message stating that Repo is initialized in your working directory. Your client directory should now contain a .repo directory where files such as the manifest will be kept.
To pull down files to your working directory from the repositories as specified in the default manifest, run
$ repo sync
By default, access to the Android source code is anonymous. To protect the servers against excessive usage, each IP address is associated with a quota. Now we switch to build a new Kernel before we come back to build ICS4.
What version of gcc and g++ to use?
Ubuntu 11 already start using gcc 4.6. So you can check your C/C++ compiler version by gcc –v to make sure your system is using gcc-4.4. You also need to make sure that you use g++ version 4.4 for CXX command.
$ gcc -v
$ gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
I am using Ubuntu 10.04LTS. So it happen on the same GCC version with Google
Using built-in specs.
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu 5)
If you are using gcc 4.6, you will always need to do “ make CC=gcc-4.4 CXX=g++-4.4.. “ for following Android build process
Building a Kernel Provided by Intel
Since Android is meant for touchscreen devices, it doesn’t include support for a mouse pointer by default, and possibly no network too as most Android devices are using wireless. To build a Android ICS 4 virtualbox for regular app development platform, we need to rebuild the kernel with mouse support as well as some of features that you probably need for your own apps. Intel Android developer site provided a Linux 2.6. kernel SDK for x86 which included many drivers that Intel developed. Go to Intel Android Developer site to download Android* 2.3.7 (Gingerbread) x86 Emulator Image Add-on. After Unzip the package Intel_x86_sysimg_2.3.7_Source_Files.zip ( 1.2G), you will find:
Run a untar to kernel_sdk_x86.tar.gz to create a new folder with the kernel 2.6.x source ( Intel soon will make new kernel for Ice Cream Sandwich 4 or higher available.However the process is similiar)
We switch to the directory that holds your kernel files. Now that we have the kernel source, we need to modify the configuration according to the hardware that you are using for Virtualbox host system and rebuild it. We can use menuconfig graphical interface provided by kernel source which will allow us to do this conveniently:
$ cp ANDROID_TOP_PATH/your_kernel_path/arch/x86/configs/vbox_defconfig .config
$ make ARCH=x86 menuconfig
It will take a few seconds to compile and load:
Once it does, use Up/Down arrows to navigate, enter to select (i.e. to expand), ‘y’ (or space) to include. e.g. to enable Mice,You will need to go to: Device Driver->Input Device Support -> Mice. To enable Wireless, you can go to Network Device Support etc. You can also see that there session dedicated for Tablet, you can go to related line and select them.
Note: menuconfig is the place that you check to make sure the required features and support for your application or system integration is supported. For App developers, it is equally important that you must test and validate your app on Android that is built with default menuconfig to guarantee the maximum compatibility of your app to various Android device made by different OEM
$ make ARCH=x86 –j32
After the compiling, if you see the last line that Kernel: arch/x86/boot/bzImage is ready .Then, your make is successful.
Add patched Kernel
Here the kernel image bzImage need to be renamed to kernel-vbox, and copied to /ANDROID_TOP_PATH/prebuilt/android-x86/kernel/kernel-vbox:
$ cp /ANDROID_TOP_PATH/kernel/arch/x86/boot/bzImage /ANDROID_TOP_PATH/prebuilt/android-x86/kernel/kernel-vbox
Setup Faster Android Builds using CCACHE
You can greatly reduce the compile time for subsequent compilations by use the compiler cache. To set up a 50GB cache ( I have a big HDD), you can run:
1. Install CCcache program and Create a directory for your ccache
$ sudo apt-get install ccache
$ sudo mkdir /ANDROID_TOP_PATH/ccache
$ sudo chown $LOGNAME /ANDROID_TOP_PATH/ccache
2. Set up your environment variables Place these in your ~/.profile,
$ sudo gedit ~/.bashrc
3. Set the ccache sizes. If you have a big hard drive, you can set it bigger:
$ ccache -F 100000
$ ccache -M 50G
Build ICS 4 with new Kernel
Setting up Environment:
$ /ANDROID_TOP_PATH/> source build/envsetup.sh
For ICS 4.0.1, you will see:
Time to time, I encounted "No Target to Make" error message when using lunch vbox_x86_eng. So it is easy to just do the following:
You're building on Linux
Lunch menu... pick a combo:
Which would you like? [full-eng] 3 (Note: make sure you select 3.vbox_x86-eng)
Run make, I have a 16-core server, so I use j=32 (double by HT).
$ make -j32
Compiling time is dependent on your hardware. Using 2.6 kernel will lead to a image file about 300 mb.
There have been issues reported by Android developer that time to time the networking does not appear to get the default DNS servers. No knowing when the related patch will be provided to ICS 4 vbox-x86 target repo. One way around this is to use some publicly available DNS servers, such as those provided by Google (126.96.36.199)(See post here ):
Build the VirtualBox Android Disk (Android_disk.vdi) and VirtualBox Android Installer
Finally, we build the Android_disk.vdi and installer_vdi together :
$ make android_disk_vdi installer_vdi -j32
If the build is successful, You will see the output below somewhere:
Done with VirtualBox bootable disk image -[ out/target/product/vbox_x86/android_disk.vdi ]-
Done with VirtualBox bootable installer image -[ out/target/product/vbox_x86/installer.vdi ]-
With android_disk.vdi (334mb), you should be able to New->Create New Virtual Machine and use android_disk.vdi as an existing and run the ICS 4 in virtualbox. Set up the parameters for virtualbox is straigfoward. Unlike the previous Android in virtualbox that you need to click Machine on top menu -> Disable Mouse Integration to enable your mouse. You just need to click inside the VirtualBox window (Press the right Ctrl key to release your mouse).
Go to setting -About this phone, and you will see your build information:
Install Android Virtualbox using installer.vdi
Even the file size in Virtualbox is expanded to ~550mb. It is still too small to load apps to test. We still need a Android installer disk to install Android into a much larger partition ( better larger than 4G ).First you start New and follow Create New Virtual Machine Wizard to create a larger disk under IDE controller. In my case, I create a 4G disk in the format of vdi fixed file, and set it as IDE Primary Master.
Then in Storage of the Settings of your virtual machine as below:
Add the installer.vdi as the Primary IDE Slave as show below. Now you can get started to install Android on the larger 4G Disk you just created.
- Start the emulator
- Use F12 to get to the BIOS boot menu. Boot to the secondary drive
- Use grub to select the Install option: 2. Boot from Primary Slave
When you see "Done processing installer config", type "reboot"
Note: The first time you install on your target virtual disk, the install will most likely fail. A message will be printed that tells you to run the installer again. You should do so:
After reboot, you can see that your Android is running from the larger disk that you create, and you can safely remove the installer.vdi from Storage under IDE Controller.
The Serial port has been enabled by default . The virtual machine needs a one-time enabling of the COM1 serial port however. The following instructions will cause VirtualBox to create a named pipe called .vbox_pipe in your home directory. From the command line:
$ VBoxManage modifyvm Android --uart1 0x03f8 4
$ VBoxManage modifyvm Android --uartmode1 server /home/user/.vbox_pipe
Or from in the GUI, use the serial ports tab to enable COM1 as a "Host Pipe" and select "Create Pipe" for it to be created as /home/user/.vbox_pipe.
To connect to this named pipe, use:
$ socat unix-client:$HOME/.vbox_pipe stdout
Note: Environment variables (e.g. $HOME) might not be understood by VirtualBox, so you will have to specify a full explicit path, like /home/user/.vbox_pipe.
The ethernet port (eth0) is enabled for DHCP in the image. To connect to it via ADB you will need the DHCP address that has been assigned.
If you are using a bridged ethernet, you may obtain this address from a shell prompt either from the serial port or from "developer tools -> terminal emulator" using the command:
If you are using a Host-only adapter, 'vboxnet0', you should use the address 192.168.56.101. to create your host-only interface, you may need to use the command:
Now you have a virtualbox completely built from Google official vbox-x86 target for Ice Create Sandwich and the Kernel of your choice, and you control what to add or remove at Kernel built or Android compile level to address your need for Apps development and testing. There are a lot of discussion of Android ICS in virtualbox that you find tips and tricks, In my case, I was able to twig and add/install apps made by Java, NDK or Chrome Web application, play around and test them:
I can also user Intel Power Monitor tool to do power related profiling and monitoring about the application: