[Android] GermainZ:
Arch Linux is a rolling release distribution, but Android requires you to have jdk6 (or openjdk6) and python2 to build it. It took me some time to setup everything, and I hope this guide will be useful to anyone who's trying to do the same.

The ArchWiki is a bit outdated. Among other things, it suggests changing the "python" symlink to point to python2, which I didn't want to do as it could cause problems ("python" is supposed to point to python3). Also, Arch Linux uses openjdk7, so you'd have to downgrade to openjdk6 (or Oracle's jdk6) - which isn't mentioned in the Wiki, and is something I'd rather avoid as I want to keep using the latest version.

Basically, I'd like to share this here for now to get some input, and later update the ArchWiki.

0- Quick note about this guide

I think it's pretty safe to assume you're familiar with the terminal. ;)

Also note that this guide will not really talk about how to actually build Android, it's focused on setting up your Arch distro to do so in an easy way.

1- Prerequisites

The ArchWiki covers installing the Android SDK and ADB pretty well.

You'll need these packages for building Android:

git gnupg flex bison gperf sdl wxgtk squashfs-tools curl ncurses zlib schedtool perl-switch zip unzip

And for 64 bit systems (make sure multilib is enabled):

lib32-zlib lib32-ncurses lib32-readline gcc-libs-multilib gcc-multilib lib32-gcc-libs

You also need the "repo" utility, which is available in the AUR.

2- Setting up Java

The AUR has packages that should install alongside openjdk7, but that didn't work for me and I found it easier to simply install jdk6 independently of pacman's packages.

To do so, download the latest Linux .bin file (jdk-6u45-linux-x64.bin), and place it in /opt (run a root shell, "sudo bash"):

cp ~/Downloads/jdk-6u45-linux-x64.bin

Make it executable and run it as root:

cd /opt
chmod +x jdk-6u45-linux-x64.bin
./jdk-6u45-linux-x64.bin

We'll be updating our path before building to use this version.

3- Setting up Python

We're going to create a python symlink to python2, and place it in /opt/android-build. We'll use this later by updating our path when necessary.

mkdir /opt/android-build
cd /opt/android-build
ln -s $(which python2) python

4- (Temporarily) Setting up our PATH to test if everything's fine

We just installed jdk6 and made a symlink to python2, but we still need to update our path. In this step, we'll do that in order to test that everything's fine:

export PATH="/opt/android-build:/opt/jdk1.6.0_45/bin:$PATH"

Make sure jdk6 and python2 are being used:

echo -n $(python -V)
echo -n $(java -version)

The output should be similar to:

Python [COLOR="Red"]2[/COLOR].x.x
java version "1.[COLOR="Red"]6[/COLOR].xx"
Java(TM) SE Runtime Environment (build 1.[COLOR="Red"]6[/COLOR].xx)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

5- Make a build script (or just build).

I'd highly suggest making a build script and placing it in ~/bin. You can then easily run it, and it will take care of everything.

Otherwise, you can run this in the terminal every time before building:

export PATH="/opt/android-build:/opt/jdk1.6.0_45/bin:$PATH"

And then proceed normally, for example:

. build/envsetup.sh
lunch cyanogen_cooperve-eng
make clean
time make -j6 bacon

This is my (trimmed down to remove some git revert checks) personal build script, you can modify it to fit your needs. The working directory is your home folder, change the "path" variable around the middle if yours is different.

Help() {
echo -n "Usage: build [OPTIONS]
-h, --help show this screen
-s, --sync run repo sync before building
-c, --clean make clean"
echo
}

box () {
tput setaf 6
echo
str="$@"
len=$((${#1}+4))
for ((i = 1; i <= $len; i++)); do
echo -n '*'
done
echo
echo "* $str *"
for ((i = 1; i <= $len; i++)); do
echo -n '*'
done
echo
tput sgr0
}

path="/home/germain/"
sync=0
clean=0
while :; do
case $1 in
-h | --help)
Help
exit 0
;;
-s | --sync)
sync=1
shift
;;
-c | --clean)
clean=1
shift
;;
--)
shift
break
;;
-*)
echo "Unknown option $1, ignoring" >&2
shift
;;
*)
break
;;
esac
done

clear
box "Setting up \$PATH..."
export PATH="/opt/android-build:/opt/jdk1.6.0_45/bin:$PATH"
echo -n $(python -V)
echo -n $(java -version)

cd "$path"

(( "$sync"==1 )) && box "Syncing..." && repo sync -j64

box "Starting build..."
. build/envsetup.sh
lunch cyanogen_cooperve-eng
(( "$clean"==1 )) && box "Clean build!" && echo && make clean
time make -j6 bacon

box "Done!"

To set it up:

nano ~/bin/build
<copy the above script, press SHIFT + INSERT to paste, and CTRL+X followed by "Y" to save>
chmod +x ~/bin/build

Usage:

Usage: build [OPTIONS]
-h, --help show this screen
-s, --sync run repo sync before building
-c, --clean make clean

Sources

These web pages helped me a lot.

http://f0rki.at/building-android-on-arch-linux-x86_64.html

https://wiki.archlinux.org/index.php/Android

https://bbs.archlinux.org/viewtopic.php?id=131939