AOSP Foundations
3 min read

Build Dependencies

Learn how to install the required system packages, libraries, and tools necessary to compile AOSP.

Even on a freshly installed Ubuntu LTS system, you cannot immediately compile Android. The AOSP build system relies on hundreds of very specific system-level libraries, compilers, and utilities that must be installed via the APT package manager.

The Essential Packages

Google provides a master list of required packages for Ubuntu. These packages include fundamental development tools like git, make, gcc, and standard C/C++ libraries that the host system needs to execute the build scripts.

To install the dependencies on Ubuntu 20.04 or 22.04, you run the following command in your terminal:

sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig

Key Dependencies Explained

While you do not need to memorize the list, it is incredibly helpful to understand why the build system needs some of the most critical packages to debug cryptic build errors:

  • bison and flex: These are parser generators. AOSP uses them to parse complex configuration files (like HIDL interfaces) and generate custom C++ code dynamically during the build.
  • build-essential: This provides the standard GNU Compiler Collection (GCC) and make tools. Even though modern AOSP uses Clang and Ninja, the legacy build scripts still require these basic tools to bootstrap the initial environment.
  • lib32z1-dev and libc6-dev-i386: AOSP heavily cross-compiles code (e.g., building ARM binaries on an x86 host). It occasionally needs 32-bit compatibility libraries on your 64-bit Ubuntu host to execute legacy proprietary prebuilt binaries supplied by silicon vendors.
  • libxml2-utils and xsltproc: Used heavily when merging and parsing the various XML manifest files across the 800+ repositories.

Prebuilts Directory

It is important to note that you do not need to install the actual Clang/LLVM compiler or Python using APT.

To guarantee that an AOSP build is completely reproducible on any machine globally, Google ships the exact versions of Clang, Python, Go, and the Ninja build system directly within the source tree inside the prebuilts/ directory. The build scripts are hardcoded to use these prebuilt binaries rather than whatever version happens to be installed on your host OS.

# Example: Running the prebuilt Clang compiler directly from the AOSP tree
./prebuilts/clang/host/linux-x86/clang-r416183b/bin/clang --version

Resolving Common Dependency Issues

If your build fails immediately with a cryptic error message mentioning a missing .so file or an "unknown command", you are almost certainly missing a system package.

  1. Read the error log carefully.
  2. Identify the missing command or library.
  3. Use the apt-file utility to determine which Ubuntu package provides the missing file, and install it.
# If the build fails because it cannot find 'm4'
sudo apt install apt-file
apt-file update
apt-file search bin/m4
# Output shows the package is named 'm4'. Install it: sudo apt install m4