Setting up Ubuntu to build Android Open Source Project (AOSP) is not very difficult, and now that AOSP recently added support for Ubuntu 11.10 it will be more appealing to people who like to run on the latest Ubuntu release. However, there are some gaps in the documentation to build AOSP on Ubuntu 11.10 successfully, so these instructions seek to fix that. The 64-bit version of Ubuntu is the recommended version for compiling AOSP, and unless you have a compelling reason to stay on a 32-bit version, it is the best way to go. With the latest version of Android, Ice Cream Sandwich (ICS), the system requirements for building AOSP have increased significantly. To successfully build AOSP, your system should have:
- 4gb of RAM or more. It may be possible to build AOSP with less than 4gb of RAM, but you will subject your hard drive to considerable swapping.
- 25gb of free disk space or more. If you will only be building one branch of AOSP, then 25gb will be sufficient. But if you plan to build more than one branch, for instance building for multiple devices, you will need more than 25gb. Additionally, if you plan to make use of caching to improve build performance (and you should if you can), then you should give yourself at least another 50gb of free space on top of that.
- A processor with multiple cores. A single core processor would be able to build AOSP, but the build time will be decreased significantly with more cores available.
- Optionally, a second physical hard drive. It’s been suggested that having AOSP source code on one physical drive, and the build output on a separate physical drive, will improve build performance.
If you don’t have a dedicated system to install Ubuntu on just for AOSP, you can install it as a virtual machine. VirtualBox and VMware Player are both cost free virtualization options. If you do install Ubuntu into a virtual machine, give it access to as many CPU cores and as much RAM as you can. Even fast systems can take an hour or more to build ICS on the first build.
Google has good instructions for setting up the build environment here which is what these instructions are based from. A fresh OS installation is assumed for these instructions, but should work on existing installs. Commands are run from the terminal.
- Make sure Ubuntu is up to date. If you have any kernel updates, now might be a good time to reboot and let those updates take effect.
- sudo apt-get update
- sudo apt-get upgrade
- Install Java. Ubuntu is no longer able to distribute Sun’s Java due to a licensing change, so it can’t be installed through apt. Download Sun’s JDK version 6 update 30 directly from Sun here. Be sure to download the Linux x64 .bin file. After it downloads, run the following commands.
- sudo chmod a+x ~/Downloads/jdk-6u30-linux-x64.bin
- sudo cp ~/Downloads/jdk-6u30-linux-x64.bin /usr/lib
- cd /usr/lib
- sudo ./jdk-6u30-linux-x64.bin
- sudo mv /usr/lib/jdk1.6.0_30/ /usr/lib/jvm/
- Determine if any other JVMs are installed, and count how many, if any.
- sudo update-alternatives ––config java
- sudo update-alternatives ––install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_30/jre/bin/java 1 (Note the number 1 is used here if no previous JVMs have been installed. Otherwise, this number should be 1 more than the number of JVMs installed.)
- sudo update-alternatives ––config java (Be sure to select Sun’s Java.)
- We need create symbolic links to a few Java binaries in /usr/bin
- cd /usr/bin
- sudo ln -s /usr/lib/jvm/jdk1.6.0_30/bin/javac
- sudo ln -s /usr/lib/jvm/jdk1.6.0_30/bin/jar
- sudo ln -s /usr/lib/jvm/jdk1.6.0_30/bin/javadoc
- We need to ensure that the AOSP build process can locate the JDK, so we will set a variable it uses to locate the JDK.
- Open .bashrc in gedit: gedit ~/.bashrc
- Add the following lines:
- ANDROID_JAVA_HOME=/usr/lib/jvm/jdk1.6.0_30
- export ANDROID_JAVA_HOME
- Save and exit gedit
- Install the required packages for building.
- 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 lib32readline-gplv2-dev lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc
- Install libX11
- sudo apt-get install libx11-dev:i386
- Install GCC 4.4, since AOSP has some incompatibilities with the included GCC 4.6 in Ubuntu 11.10.
- sudo apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib gcc-4.4-multilib
- Since we want to use GCC 4.4 instead of GCC 4.6 to build AOSP, we should make an alias rather than specify which GCC to use when we run make in AOSP.
- Open ~/.bashrc in gedit: gedit ~/.bashrc
- Paste the following line: alias make_aosp='make CC=gcc-4.4 CXX=g++-4.4'
- Save and exit gedit
- Create a symbolic link for libX11.
- sudo ln -s /usr/lib/i386-linux-gnu/libX11.so.6 /usr/lib/i386-linux-gnu/libX11.so
- Configure USB access
- sudo touch /etc/udev/rules.d/51-android.rules
- sudo gedit /etc/udev/rules.d/51-android.rules
- Paste the follow in the empty file and save, then close gedit (be sure to replace <username> with your username): # adb protocol on passion (Nexus One) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e12″, MODE=”0600″, OWNER=”<username>” # fastboot protocol on passion (Nexus One) SUBSYSTEM==”usb”, ATTR{idVendor}==”0bb4″, ATTR{idProduct}==”0fff”, MODE=”0600″, OWNER=”<username>” # adb protocol on crespo/crespo4g (Nexus S) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e22″, MODE=”0600″, OWNER=”<username>” # fastboot protocol on crespo/crespo4g (Nexus S) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e20″, MODE=”0600″, OWNER=”<username>” # adb protocol on stingray/wingray (Xoom) SUBSYSTEM==”usb”, ATTR{idVendor}==”22b8″, ATTR{idProduct}==”70a9″, MODE=”0600″, OWNER=”<username>” # fastboot protocol on stingray/wingray (Xoom) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”708c”, MODE=”0600″, OWNER=”<username>” # adb protocol on maguro/toro (Galaxy Nexus) SUBSYSTEM==”usb”, ATTR{idVendor}==”04e8″, ATTR{idProduct}==”6860″, MODE=”0600″, OWNER=”<username>” # fastboot protocol on maguro/toro (Galaxy Nexus) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e30″, MODE=”0600″, OWNER=”<username>” # adb protocol on panda (PandaBoard) SUBSYSTEM==”usb”, ATTR{idVendor}==”0451″, ATTR{idProduct}==”d101″, MODE=”0600″, OWNER=”<username>” # fastboot protocol on panda (PandaBoard) SUBSYSTEM==”usb”, ATTR{idVendor}==”0451″, ATTR{idProduct}==”d022″, MODE=”0600″, OWNER=”<username>”
- Open gedit and paste the following at the end of the file, then save and close:
- Open .bashrc in gedit: gedit ~/.bashrc
- Paste the following at the end of the file: export USE_CCACHE=1
- Save and exit gedit
- Set the CCACHE size. The CCACHE size should be between 50-100gb, depending on how many branches you intend to build.
- prebuilt/linux-x86/ccache/ccache -M 50G
- Download the Android SDK for Linux from here and then extract it. For purposes of these instructions, we will use ~/code folder for holding the Android SDK and later AOSP, but you can change it to any location you prefer.
- tar -zxf ~/Downloads/android-sdk_r16-linux.tgz -C ~/code
- Run the Android SDK Manager and install everything under Android 4.0.3 (API 15). Also install Android SDK Tools and Android SDK Platform-tools.
- ~/code/android-sdk-linux/tools/android
- Now we need to add ~/code/android-sdk-linux/platform-tools to the PATH. We need to use the full path to platform-tools, so adjust your path accordingly.
- Open .bashrc in gedit: gedit ~/.bashrc
- Paste the following line at the end of the file: export PATH=$PATH:/home/jon/code/android-sdk-linux/platform-tools:/home/jon/code/android-sdk-linux/tools
- Paste the following line at the end of the file below the one from above: alias sudo=’sudo env PATH=$PATH’
- Save and exit gedit
Your Ubuntu system is now ready to download and build AOSP. You’ll need to log out and log back in for the PATH variables to take effect. Very good instructions for downloading AOSP can be found here.
References: