Experimenting with custom ROMs can be a pain if not built correctly. Devices might be “bricked” if a ROM is broken (meaning that the device will be rendered useless). The Android emulator (part of the Android SDK package) offers a good device alternative for testing your ROM. A drawback of the Emulator is that, as its own name implies, has to be emulated on your machine in order to work. This means that it will run quite slowly compared to a real device such as an Android-powered tablet or phone. Justin’s previous blog post explains how emulator computation speed can be improved by utilising x86 architecture-based images rather than the ARM architecture found in most Android devices.
In this post I explain how to build x86 images as an alternative to the more common ARM images. This post relies on the method released by Google themselves, which unfortunately fails to explain a common problem that some developers find when building the image. The problem involves failure of DNS server configuration. The browser will connect to servers using IP addresses but then fail to connect using domains. This is quite annoying if like me you need to test a web-based application. Here we cover the basics of building x86 based images as well as the DNS issue. For users who have already built their image, skip to the end of this post.
To prepare the environment for building, install the following (assuming you are running Ubuntu 12.04):
sudo apt-get install git 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 tofrodos
python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
if the above 2 commands produce errors, try this first:
sudo apt-get install gcc-multilib
Now that the environment is ready, the sources can be downloaded.
Any necessary changes to your ROM should be done at this stage before building.
Next, we must build the downloaded Android sources. This will compress the sources into a “system.img” file, which we will flash the device with (in the case of experimentation, the emulator). The only change required to specify a build for an x86 architecture instead of ARM is by specifying a different “lunch” command: “lunch full_x86-eng”.
For the tricky part, we will now change the DNS configuration so that domains will work as well. We need to customise the “system.img” file we just created. Two tools are needed for this: unyaffs and mkyaffs2image.
This tutorial provides guidelines on how to utilise both tools.
Once “system.img” is extracted, we need to modify the file “build.props” and set the DNS configuration there. Simply append “net.dns1=220.127.116.11” at the end of the file and re-build “system.img” using mkyaffs2image.
The resulting “system.img” file is to be copied into a specific folder for the emulator to load it. From the Android SDK Manager, download the Intel x86 Android image of the API version chosen when downloading the sources. For example, if the Android API version of choice when building the custom ROM is 16 (version 4.1.2), replace the custom “system.img” that we have just built in the directory “<root-of-android-sdk>/system-images/android-16/x86″. As a word of warning, I would recommend you do a backup first.
Follow the steps in Justin’s blog post to make the emulator faster (link above) and then launch the emulator with the custom image. (If a stock x86 image was already being used, make sure you wipe the device before launching the emulator and after replacing “system.img”). You should now be able to launch a custom x86 architecture-based ROM with a proper DNS server configuration. 🙂