This section describes how to set up your local work environment to build
the Android source files. You must use Linux; building under either MacOS or
Windows isn't supported. Keep in mind the important change to the
binary as well.
For an overview of the entire code-review and code-update process, see Life of a patch.
Choosing a branch
Some requirements for the build environment are determined by the version of
the source code that you plan to compile. For a full list of available branches,
see Build Numbers. You can also
choose to download and build the latest source code (called
main), in which case you simply omit
the branch specification when you initialize the repository.
After selecting a branch, follow the appropriate instructions below to set up your build environment.
Setting up a Linux build environment
These instructions apply to all branches, including
The Android build is routinely tested in house on Ubuntu LTS (14.04) and Debian testing. Most other distributions should have the required build tools available.
For Gingerbread (2.3.x) and higher versions, including the
branch, a 64-bit environment is required. Older versions can be
compiled on 32-bit systems.
Installing required packages (Ubuntu 18.04 and higher)
You need a 64-bit version of Ubuntu.
sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 libncurses5 x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig
Installing required packages (Ubuntu 14.04)
You need a 64-bit version of Ubuntu (14.04 is recommended).
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev libgl1-mesa-dev libxml2-utils xsltproc unzip
Installing required packages (Ubuntu 12.04)
You may use Ubuntu 12.04 to build older versions of Android. Version 12.04
isn't supported on
main or recent releases.
sudo apt-get install git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
Installing required packages (Ubuntu 10.04-11.10)
Building on Ubuntu 10.04-11.10 is no longer supported, but may be useful for building older releases of AOSP.
sudo apt-get install git gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev libgl1-mesa-dev mingw32 tofrodos python-markdown libxml2-utils xsltproc
On Ubuntu 10.10:
sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so
On Ubuntu 11.10:
sudo apt-get install libx11-dev:i386
Configuring USB access
Install a community-maintained default set of
udev rules for
all Android devices by following the instructions to Set up a device for development.
Using a separate output directory
By default, the output of each build is stored in the
subdirectory of the matching source tree. You can override this by exporting
OUT_DIR environment variable. For example:
This will cause the output of the build to be stored in the
subdirectory of the source tree. When using the same source tree to build for multiple targets, it
is recommended to use a separate
OUT_DIR for each target.
On some machines with multiple storage devices, builds are faster when storing the source files and the output on separate volumes. For additional performance, the output can be stored on a file system optimized for speed instead of crash robustness, because all files can be regenerated if the file system is corrupted.
To set this up, export the
to point to the location where your output directories
will be stored.
The output directory for each separate source tree is named after the
directory holding the source tree. For instance, if you have source trees
/source/main2 and if
OUT_DIR_COMMON_BASE is set to
/output, the output
Avoid having multiple source
trees stored in directories that have the same name,
as the source trees would end up sharing an output directory, with
unpredictable results. This is only supported on Jelly Bean (4.1) and higher,
Next: Download the source
Your build environment is good to go! Proceed to downloading the source.