
There are many tasks that require rebuilding the kernel and the Android operating system as a whole. For example, creating and debugging your own modules, including support for profiling the system and simply testing your applications on the new version of Android.
The ability to run Android x86 inside a virtual machine VirtualBox allows enthusiasts and creators of firmware to dig into the system settings, configure and rebuild the kernel and not “brick out” the real device. VirtualBox provides the ability to use OS debugging tools familiar to the Linux developer. For ordinary developers of Android applications, an emulator using Intel Hardware Accelerated Execution Manager technology is perfect. (you can read more
here )
The article provides a number of practical tips for building an Android x86 image for running under a VirtualBox virtual machine and building an emulator. The source code for Android is taken from the official repository of the
AOSP (Android Open Source Project) project; the adapted version of the Linux 2.6 kernel from Intel is used as the core.
Setting the build environment
Android build will require a 64 bit version of Linux. Another important point: pay attention to the version of GCC that is installed on the system. Google supports GCC version 4.4 and above. Also on the system must be installed Java implementation from Oracle.
Install additional dependencies for Ubuntu 12.04:
sudo -i apt-get update sudo apt-get install git-core gnupg flex bison gperf build-essential \ zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \ libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \ libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos \ python-markdown libxml2-utils xsltproc zlib1g-dev:i386
Install a symbolic link to resolve the naming conflict:
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
Downloading the source tree
Repo Setup
Repo is a repository management utility that simplifies Git for Android. More information can be found here (http://source.android.com/source/version-control.html)
To install, initialize, and configure Repo, complete the following steps:
• Make sure you have the bin directory in your home directory and it is listed in the PATH:
mkdir ~/bin PATH=~/bin:$PATH
• Download the Repo script and set permissions for execution:
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo chmod a+x ~/bin/repo
Initializing Repo Client
After installing Repo, configure access to the Android source repositories:
• Create an empty directory for the source files and navigate to it. For example, it might look like this:
mkdir aosp cd aosp
• Run the repo init script to update the version of the Repo itself.
repo init -u https://android.googlesource.com/platform/manifest
This command will connect the master branch from the Android source tree. You can specify any other using the -b switch:
repo init -u https://android.googlesource.com/platform/manifest -b android-4.1.1_r6
To view all available branches, enter the command:
git --git-dir .repo/manifests/.git/ branch -a
We are interested in the most recent versions of Android from Google:
- Jelly Bean: remotes / origin / android-4.1.1_r6
- Ice Cream Sandwich: remotes / origin / android-4.0.4_r2.1
You can choose any to your taste, the next steps will not be different. To demonstrate the build process under VirtualBox, take the Jelly Bean (JB) version.
In case of successful initialization, you will see a message that the Repo is initialized in your directory and the folder .repo appears in it.
File upload
To download the source files from the repository to your working directory, run the following command:
repo sync -j 16
Initial synchronization may take more than an hour.
Kernel build
Android is primarily designed for gesture-driven devices and does not support the default mouse. Therefore, as an example, we will rebuild the kernel from the source code with mouse support included.
Create a directory for storing kernel sources:
mkdir ~/android_kernel cd ~/android_kernel
We use the pre-prepared version of the kernel from Intel:
wget http://software.intel.com/sites/landingpage/android/Intel_x86_sysimg_2.3.7_Source_Files.zip unzip Intel_x86_sysimg_2.3.7_Source_Files.zip tar -xvf kernel_sdk_x86.tar.gz
Go to the kernel directory:
cd kernel
Now we have the kernel source. It is necessary to modify the configuration file and rebuild. To reduce the time to complete the configuration of the kernel, we use the configuration file that we prepared for the developers. The important point - do not forget to specify the architecture for which the kernel is being built, in our case it is x86.
cp arch/x86/configs/vbox_defconfig .config make ARCH=x86 menuconfig
After a few seconds, the graphical kernel configuration menu will load. Arrows "up", "down" you can move through the menu items, "Enter" to enter the submenu. Everything is just like with the usual Linux kernel.

To enable mouse support:
• Go to "Device Drivers"
• Select “Input device Support”
• Check "Mice"
You can go to the “Mice” submenu and see the advanced driver settings.
Then exit the kernel configuration menu. This can be done with a few clicks on “Esc”. Do not forget to save the settings when the configuration menu prompts you to do this.
After making the necessary kernel settings, we will assemble it. This does not take much time, especially if you are using a multi-core machine — you can specify the make command option: -j N, where N is the number of kernels (for example, make -j 32 was used to write the article).
make ARCH=x86 –j 32
When compiling successfully, you will see the message:
Kernel: arch/x86/boot/bzImage is ready
The path to the new kernel is indicated in the last line.
Kernel substitution
The path to the kernel that will be used in the assembly for VirtualBox can be determined as follows:
grep "LOCAL_KERNEL :=" ~/aosp/build/target/board/vbox_x86/device.mk
It should look like the following:
LOCAL_KERNEL := prebuilt/android-x86/kernel/kernel-vbox
Copy the bzImage by the found path:
cp ~/kernel/arch/x86/boot/bzImage ~/aosp/prebuilt/android-x86/kernel/kernel-vbox
Build Android
Set the build environment:
cd ~/aosp . ./build/envsetup.sh
Now everything is ready to start compiling Android sources. The first step is to specify the target for the assembly:
lunch vbox_x86-eng
After executing the command, you will see information about the upcoming build:
============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=4.1.1 TARGET_PRODUCT=vbox_x86 TARGET_BUILD_VARIANT=eng TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=x86 TARGET_ARCH_VARIANT=x86 HOST_ARCH=x86 HOST_OS=linux HOST_OS_EXTRA=Linux-2.6.32-131.0.15.el6.x86_64-x86_64-with-redhat-6.1-Santiago HOST_BUILD_TYPE=release BUILD_ID=JRO03R OUT_DIR=out ============================================
Then you need to start the source build with the make command. It is considered good practice to save the build log, this can be done with the help of the tee utility.
make –j 16 | tee vbox_build.log
The assembly process can take considerable time, specific figures depend on the power of the CPU and the amount of RAM in the machine. On the system that was used to prepare the article, it took about an hour. The recommended number of threads for an assembly can be determined at the rate of 2GB of RAM per stream.
If the compilation is successful, the last line of the output will contain the path and size of the image:
Install system fs image: out/target/product/vbox_x86/system.img out/target/product/vbox_x86/system.img+ total size is 268435456
Next, you need to build a boot image for VirtualBox:
make installer_vdi
If the build was successful, the following entry should appear in the console:
Done with VirtualBox bootable installer image -[ out/target/product/vbox_x86/installer.vdi ]-
Configure VirtualBox
Now we are going to configure VirtualBox. We need to create a new virtual machine, call it “Android_ICS”, choose Linux as the operating system, and set the version to Other as the most suitable for Android.

The next step is the allocation of RAM. 512 megabytes and more are recommended. In our case it will be gigabyte.

Next, adjust the size of the hard disk. The main thing is that after the setup is completed, all VirtualBox hard drives are connected to the IDE controller.
Install the Android boot image as the second partition of our virtual machine.

When you first start the virtual machine, we need to start the installation of Android. During startup, press F12 to enter the BIOS settings menu. Select 2 “Primary Slave”, this is where the Android installation image is located.
If the installation is successful, you will see “Done processing installer config”. Sometimes when you first install errors may occur, just run it again. Then reboot the virtual machine into your newly installed Android!

Jelly Bean Emulator
Build emulator is not much different from the build version for VirtualBox. If you already have the source code, then proceed to the assembly from the environment initialization step. For the purity of the experiment, the process of building an emulator will be described from the very beginning. Therefore, we will create a separate directory for the Jelly Bean Emulator and repeat the already familiar steps.
mkdir ~/jb cd ~/jb
Repository Initialization
repo init -u https://android.googlesource.com/platform/manifest -b android-4.1.1_r6
Download Source Code
repo sync -j 16
Initialization of the environment
. ./build/envsetup.sh
Emulator Assembly Selection
lunch full_x86-eng
If successful, you will see:
============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=4.1.1 TARGET_PRODUCT=full_x86 TARGET_BUILD_VARIANT=eng TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=x86 TARGET_ARCH_VARIANT=x86-atom HOST_ARCH=x86 HOST_OS=linux HOST_OS_EXTRA=Linux-2.6.32-131.0.15.el6.x86_64-x86_64-with-redhat-6.1-Santiago HOST_BUILD_TYPE=release BUILD_ID=JRO03L OUT_DIR=out ============================================
Run the build:
make –j 16 | tee emulator_build.log
While the compilation process is in progress, copy the configuration file and build the kernel for the emulator.
cd kernel cp arch/x86/configs/goldfish_defconfig .config make ARCH=x86 -j16
Now the emulator build is complete.
The easiest way to run it:
emulator
For example, you can run with a newly assembled kernel, with a resolution of 480x800, 512 megabytes of RAM and hardware graphics acceleration enabled.
emulator -kernel ~/kernel/arch/x86/boot/bzImage -skin WVGA800 -memory 512 -gpu on
More details about the features and settings of the emulator can be found
here.
Conclusion
This article describes how to install the Android x86 version of Jelly Bean for VirtualBox, building a customized kernel and emulator. There are many different tricks and approaches to the construction and configuration of various versions of Android, which remained outside the scope of this article. Here was laid out the basic material in order to start your way into the world of the Android OS.