Each revision of Android is meant to be compiled with a specific set of dependencies. No effort is made upstream to support multiple build environments.
Building with different environments often yields build errors due to untested dependencies versions.
So we document here how to recreate these recommended build environments.

Recommended environment history

Ubuntu support:

          ,2013-10-15 - Lucid   (10.04)
2013-10-15,2015-03-16 - Precise (12.04), probably with 4.4 KitKat - https://web.archive.org/web/20131015123913/http://source.android.com/source/initializing.html
2015-03-16,           - Trusty  (14.04) https://web.archive.org/web/20150316053136/https://source.android.com/source/initializing.html

Java support:

          ,2014-03-31 - Sun JDK 5/6
2014-03-31,           - OpenJDK 7 - https://web.archive.org/web/20140331004436/https://source.android.com/source/initializing.html

Ubuntu 14.04

With LXC:

lxc-create -n android-14.04 -t download -- -d ubuntu -r trusty -a amd64

lxc-start -n android-14.04 -d
lxc-attach -n android-14.04

# clean-up non-free sources
sed -i -e 's/ restricted//' -e 's/ multiverse//' /etc/apt/sources.list
apt-get update

With Docker:

docker run --name tmp -ti ubuntu:14.04 bash -c 'sed -i -e "s/ restricted//" /etc/apt/sources.list && apt-get update'
docker commit tmp ubuntu:14.04

Ubuntu 10.04

With LXC:

apt-get install ubuntu-archive-keyring rsync
lxc-create -n android-10.04 -t ubuntu -- -r lucid -a amd64

lxc-start -n android-10.04 -d
lxc-attach -n android-10.04

# clean-up non-free sources
sed -i -e 's/ restricted//' -e 's/ multiverse//' /etc/apt/sources.list
apt-get update

You'll need git > 1.7.2 for repo:

cd /usr/src/
apt-get install wget gcc libssl-dev zlib1g-dev libcurl4-gnutls-dev libexpat-dev gettext
wget https://www.kernel.org/pub/software/scm/git/git-2.4.6.tar.gz
tar xf git-2.4.6.tar.gz 
cd git-2.4.6/
make -j4  # ~2mn
make install prefix=/usr/local

If network access is necessary:

# 'lxcguest' fixes a number of issues but seem to disable init..
/etc/init.d/ssh restart


Some shell scripts assume /bin/sh is bash:

echo 'dash dash/sh boolean false' | debconf-set-selections
dpkg-reconfigure --pri=high dash

Let's avoid Recommended packages for better dependencies control:

echo 'APT::Install-Recommends "false";' > /etc/apt/apt.conf.d/00InstallRecommends