How to download Android source code

Source code of Android can be downloaded by following these steps:

$ mkdir ~/bin
 $ PATH=~/bin:$PATH
 $ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
 $ chmod a+x ~/bin/repo
 $ mkdir WORKING_DIRECTORY
 $ cd WORKING_DIRECTORY
 $ repo init -u https://android.googlesource.com/platform/manifest
 $ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
 $ repo sync

android-4.0.1_r1 can be replaced by any version displayed in the previous step. The download process will take a while.