July 9, 2025
8 min read

Cloning and Building AOSP: A Step-by-Step Guide

AOSP
Android
Build
Source
Development
SSamir Dubey
Samir Dubey

AOSP Engineer

A practical guide to cloning and building the Android Open Source Project (AOSP) from source, including repo initialization, syncing, and build commands.

In this article, we will delve into the process of cloning AOSP source code, an essential step for developers who wish to explore and contribute to the Android platform. Cloning AOSP allows developers to have a local copy of the complete Android source code, enabling them to build and modify the operating system to suit their needs.

Before we begin, please note that this guide assumes you have a basic understanding of version control systems and are familiar with using the command-line interface on your computer.

Step 1: Install Required Ubuntu Packages

First, ensure that you have the necessary packages installed on your Ubuntu system. These packages are essential for building AOSP.

Command:

sudo apt-get install -y git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip genisoimage android-tools-adb android-tools-fastboot minicom m4 liblz4-tool libssl-dev

Step 2: Install Repo Tool

The Repo tool is used to manage multiple Git repositories and is essential for cloning AOSP.

mkdir ~/bin****curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo****chmod a+x ~/bin/repo

Then, add the Repo tool to your system’s path by editing the ~/.bashrc file:

sudo vi ~/.bashrc

Add the following line at the bottom of the ~/.bashrc file:

PATH=~/bin:$PATH

Save and close the file, then run the following command to apply the changes to the current session:

source ~/.bashrc

Step 3: Cloning Source Code

Now that you have set up the required tools, let’s proceed with cloning the AOSP source code.

1. Creating a Working Directory:

Create a directory on your computer where you want to store the AOSP source code. For example, you can create a folder named “AOSP” on your desktop.

mkdir ~/Desktop/AOSP****cd ~/Desktop/AOSP

2. Initializing the Repository:

The AOSP source code is stored in a Git repository. To initialize the repository, use the following command:

repo init -u https://android.googlesource.com/platform/manifest -b <branch>

This command will fetch the latest AOSP manifest, which specifies the repositories and branches required to build Android.

3. Synchronizing the Repository:

Once the repository is initialized, you can synchronize it to download the source code:

repo sync

This process may take some time, depending on your internet connection and the size of the AOSP source code.

Step 4: Compiling the Source Code

Before building AOSP, you need to set up the build environment. The configuration can vary depending on the target device and your development needs.

1. Configuring Build Environment:

For example, to set up the environment for building AOSP for a specific device, you can use:

source build/envsetup.sh****lunch

The “lunch” command will present you with a list of device configurations to choose from. You can select the desired option by entering the corresponding number

2. Building AOSP:

Finally, you can initiate the build process using below command:

mka -j12

Here’s a brief explanation of the build arguments used:

-j: Number of build jobs to run in parallel (e.g., -j8)

Please note that you can customize the build arguments according to your specific requirements. For example, you can exclude the arguments related to building uboot or the kernel if they are not needed for your project.

Cloning the AOSP source code and compiling it is an essential step for developers who wish to contribute to the Android platform or create their versions of the operating system. This guide provided step-by-step instructions for installing the required packages, setting up the Repo tool, cloning the source code, and building AOSP with various build commands and arguments. To delve deeper into Android development and customization, continue exploring the vast resources and documentation available in the Android Open Source Project community. Happy coding!