Building the Android Open Source Project

Working on the Android platform is a task addressed by Google and OEMs mostly. In this tutorial, you’ll get insights into building the AOSP. By Antonio Roa-Valverde.

Leave a rating/review
Download materials
Save for later

Android is the most frequently-installed operating system in the world. It’s available for phones, wearables, TVs and cars, among other devices.

Google leads the development of Android in the scope of the Android Open Source Project (AOSP), but the project also accepts public contributions.

While you might not have considered diving into the innards of Android before now, doing so will bring you new perspectives and help you understand common tooling and code patterns in Android app development. Being able to understand and change the behavior of the Android platform opens numerous possibilities to shape popular consumer devices.

In this tutorial, you’ll get an introduction to Android platform development. In the process, you’ll learn to:

  • Set up your computer to build the AOSP.
  • Get AOSP sources.
  • Build the Android emulator from the sources.
  • Change the AOSP code to replace the boot animation.

If you’d like more information, a great way to start learning Android app development is with our Your First Kotlin Android App tutorial. Better yet, dive in with the Android Learning Path and really sharpen your skills.

Note: Android platform development is quite different from Android app development. Knowing how to develop apps is beneficial to complete this tutorial, but not required.

If you’d like more information, a great way to start learning Android app development is with our Your First Kotlin Android App tutorial. Better yet, dive in with the Android Learning Path and really sharpen your skills.

Keep in mind that Android platform development can be difficult to digest at first. You’ll find less documentation than is available for Android app development, and the size of the AOSP source tree and the mix of different technologies make learning complex.

But while understanding the different parts of the Android platform requires time and effort, it’s absolutely possible to accomplish. This tutorial will help.

Now, it’s time to start a very exciting quest and enter the depths of the Android dungeons.

Getting Started

Download the starter project by clicking the Download Materials button at the top or bottom of the tutorial.

You’ll find a file containing the animation for the Android version that you’re about to build. You don’t need to worry about designing your own animation — the team has you covered. The result looks like this:

custom boot animation

Note: If you want to design your own animation from scratch, you can do so with Adobe After Effects or similar software. Just make sure to export the graphics and zip the data as explained later in this tutorial.

You’ll now learn to download the AOSP sources and create your own build.

Setting up the Development Environment

Before starting, you should know that building the AOSP has some requirements. You’ll need a computer with at least 300 GB available (yes, 300!). Since you’ll download a lot of data, you’ll also need a reliable internet connection.

When it comes to the work environment, AOSP doesn’t currently support Windows. You could use macOS, but the most common OS for working with the AOSP is Ubuntu Linux, which this tutorial will focus on.

If you’re still interested in macOS, check out the official Google documentation for setting up a macOS build environment.

In this tutorial, you’ll rely on Docker to configure your development environment using an Ubuntu container running on a Linux host. You could use the Linux host directly, but by using Docker you can separate both environments. This is useful in case your host OS uses different versions of the libraries you’ll need here.

Note: Since Docker is part of the setup, you might think that you could use macOS and Windows as well. While this is true, the fact that Docker doesn’t run natively on macOS / Windows as it does on Linux will have a huge impact on performance. This is due to the heavy I/O during the build process.

Configuring the Ubuntu Container

This tutorial assumes you already have Docker installed on your computer. If this isn’t the case, please refer to the official Docker documentation for installation instructions.

Once you have Docker running on your computer, hold tight because the fun starts now! :]

Open a terminal and run the following command:

docker pull ubuntu:18.04

This command will download the official Ubuntu 18.04 image from Docker Hub.

Next, run the following command to make sure that everything’s in place:

docker image ls

This lists all Docker images available on your machine. Make sure the Ubuntu image appears in the list before proceeding to the next step.

Available docker images

Create an empty folder called aosp in an easy-to-find location — for example, under your Desktop path: ~/Desktop/aosp. You’ll use this folder as the workspace for building the AOSP sources.

Starting the Ubuntu Container

Next, execute the following command:

docker run -v ~/Desktop/aosp:/home/aosp -it ubuntu:18.04

This will start a container based on the Ubuntu image, while at the same time sharing the folder you just created.

You share this folder with the Docker container so you can access it later from your computer — that is, directly from your system, outside the Docker container. After this, your terminal prompt will change to root, showing that you are inside the Docker container.

Make sure you have access to /home/aosp by running ls /home/aosp. If you get a message like No such file or directory, the Docker container can’t see the folder you passed in the previous command with parameter -v.

Repeat the steps above to validate you have access to the folder `/home/aosp` from within docker container.

Updating the Container and Installing Packages

Now, run the following command to update the Ubuntu packages in the container:

apt-get update

You should see the following output in your terminal:

Apt-get update response

Next, you need to install several packages you need to compile the AOSP sources during the build process. Do this by running the following command:

apt-get install -y git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib x11proto-core-dev libx11-dev libgl1-mesa-dev libxml2-utils xsltproc unzip python python3 openjdk-8-jdk rsync
Note: This might take a few minutes to complete.

Now that you’ve set up Ubuntu, you’ll get to know a tool that will help you download the Android sources more efficiently.