The source code for Android 4.0 “Ice Cream Sandwich” was released last week, and Google’s build instructions list Ubuntu 10.04 as the only officially “supported” configuration for building AOSP on Linux. As of this writing Ubuntu 10.04 is a year and a half old, so lots of people have moved on to newer versions, some of which cause problems due to missing/renamed packages, conflicting versions, etc.
Ubuntu 11.10 in particular is troublesome because it uses
gcc-4.6 by default and has no
sun-java6-jdk in its repositories. Here’s what you’ll need to do to get AOSP 4.0.x to compile on Ubuntu 11.10.
Compilers, parsers, file-manipulation tools, libraries, etc; this is mandatory! The list on the
source.android.com Inititalizing a Build Environment page is similar, but a few of those packages don’t exist in 11.10. Use these:
$ sudo apt-get update $ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \ x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils
Install an “old” GCC
In addition to building applications for the phone, Android’s build system builds a few tools for the host operating system (such as the tools in the SDK). The initial release of the Ice Cream Sandwich source code has a few incompatibilities with the version of the GNU C compiler which comes with Ubuntu 11.10 (GCC 4.6). Install GCC 4.4 from Ubuntu’s repositories:
$ sudo apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib gcc-4.4-multilib
Small fix for
libX11, which some statically-linked programs might need:
$ sudo ln -s /usr/lib/i386-linux-gnu/libX11.so.6 /usr/lib/i386-linux-gnu/libX11.so
Download Sun Java 6 JDK
Android 2.3+ requires Java 6 to build correctly. While OpenJDK did work for 2.3, it doesn’t work for Android 4.0; you need Sun Java. Download the JDK 1.6 binary release from Sun’s Java download site and unzip it somewhere in your system, for example:
$ sudo mkdir -p /opt/java/64/ $ sudo cp jdk-6u29-linux-x64.bin /opt/java/64 $ sudo su - $ cd /opt/java/64 $ chmod +x jdk-6u29-linux-x64.bin $ ./jdk-6u29-linux-x64.bin $ exit
Add the new Java to your shell environment’s
$PATH so it takes precedent over other Javas you might have installed:
$ echo 'export PATH=/opt/java/64/jdk1.6.0_29/bin:$PATH' >> ~/.bashrc
Relaunch your terminal and test,
$ java version "1.6.0_29" Java(TM) SE Runtime Environment (build 1.6.0_29-b11) Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02, mixed mode)
Follow Google’s Downloading the Source Tree, which will help you install the
repo tool and clone the
android-4.0.1_r1 branch. It’s damn near 9 gigabytes, so make sure you have a fast Internet pipe and a pot of coffee ready.
After that you’ll be ready to build:
$ cd ~/android/ics $ lunch full-eng $ make CC=gcc-4.4 CXX=g++-4.4 -j4
On my dual-core Core i7 Thinkpad T420 with 8GB of RAM this takes ~110 minutes, your mileage may vary depending on the number of available cores, amount of RAM, and speed of your hard drive(s).
If your build completes successfully you’ll be able to test it immediately using the
emulator command (a version of QEMU, built as part of the build process):