Setting up a chroot for Android platform development

Introduction

Since Ubuntu 10.04 is still the only fully supported OS when building the Android source code (according to http://source.android.com/source/initializing.html), you might run into trouble when trying to compile it on an OS with different versions of the tools used in the build process. This happened to me when trying to compile Android ICS (4.0.1_r1) on my Arch Linux installation. Arch Linux is a rolling distribution, which means that packages are updated continuously, and my current GCC version is 4.7.1. Ubuntu 10.04 on the other hand uses an older version of the same compiler (http://packages.ubuntu.com/lucid/build-essential). This is true for most of the tools involved in the build process. One way to set up an environment that is similar to Ubuntu 10.04 is to use a chroot. In the chroot, you cannot access files or commands from outside that environment, which also means all tools needed for the build have to be installed inside the chroot, making sure non of them link to any outside libraries or files.

I will use the tools debootstrap for installing a debian base system (Ubuntu 10.04) in a chroot environment, and schroot for entering/exiting/running commands in the chroot. I will show you how to do this on Arch Linux, Gentoo and Ubuntu.

Installation

Arch Linux

Install the schroot package:

https://gist.github.com/3749558#file_install_schroot.sh

Download and build the debootstrap package from AUR (https://aur.archlinux.org/packages.php?ID=2970):

https://gist.github.com/3749558#file_install_debootstrap.sh

Ubuntu

Install the schroot and debootstrap packages:

https://gist.github.com/3769389#file_ubuntu_install_schroot.sh

Gentoo

Install the schroot and debootstrap packages:

https://gist.github.com/3772802#file_gentoo_install_schroot.sh

All

Install Ubuntu 10.04 (Lucid) in chroot environment using debootstrap, where /path/to/chroot is the directory where you want to setup the chroot:

https://gist.github.com/3749558#file_create_chroot.sh

Wait a while…

Configure schroot

Edit /etc/schroot/schroot.conf:

https://gist.github.com/3749558#file_configure_schroot.sh

Arch Linux only

Comment out networks in /etc/schroot/default/nssdatabases:

https://gist.github.com/3749558#file_nssdatabases

Prepare schroot for Android development

Change to schroot environment:

https://gist.github.com/3749558#file_run_schroot.sh

I get some errors I could safely ignore, e.g. E: 15binfmt: which: no update-binfmts in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin).

Update /etc/apt/sources.list (you can use http://repogen.simplylinux.ch/generate.php to generate your own config):

https://gist.github.com/3749558#file_sources.list

Next, update apt (apt-get update && apt-get upgrade) and install the development environment according to http://source.android.com/source/initializing.html. First thing is to install Oracle JDK6, which must be downloaded from Oracle’s homepage (http://www.oracle.com/technetwork/java/javase/downloads/index.html). One neat thing is that your home directory is actually mounted on the chroot users home directory, giving you easy access to all your user files. You can use this to simply download the Java installer to your home directory and then, in the chroot environment copying it to the target directory (e.g. /opt) and executing it:

https://gist.github.com/3749558#file_install_java.sh

Then install the required packages and create symlink for libGL:

https://gist.github.com/3749558#file_install_tools.sh

After installation of tools, there is no need to be logged in as root anymore. Log out and log in as another user:

https://gist.github.com/3749558#file_login_as_user.sh

The rest of the setup process for Android source is well documented in http://source.android.com/source/initializing.html.

This Post Has 4 Comments

  1. Thanks for the tip on schroot!

  2. I couldn’t even successfully do it in Ubuntu :( Me, crazy n00b :( thnx for the Tut man! Will try it out :-)

  3. Thanks for the blog post! Worked for me in Arch Linux. Had some problems with upgrading the rsyslog package in the new system, but it all works after replacing rsyslog with syslog-ng :)

  4. This is a great tip indeed.

    Before installing the required packages, I had to create the group ‘staff’ as xml-core failed.

    # groupadd staff

Leave a Reply

Close Menu