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.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Building the Android Open Source Project
20 mins
- Getting Started
- Setting up the Development Environment
- Configuring the Ubuntu Container
- Starting the Ubuntu Container
- Updating the Container and Installing Packages
- Using the Repo Tool
- Getting the Sources
- Initializing the Source Folder
- Downloading the Source
- Building the AOSP
- Running the Build
- Setting up the Android Bootloader Animation
- Looking at the Boot Animation Format
- Understanding the Components
- Customizing the Boot Animation
- Where to Go From Here?
Getting the Sources
Before downloading the Android sources with Repo, you need to set up your user name and email address in Git. Without them, Repo will stop and won’t download anything.
Use this command to quickly check if they’re available:
git config -l
If they’re configured, you should see something like the following in your terminal:
user.email=you@email.com
user.name=you
If this isn’t the case, run the below to set up your username:
git config --global user.name "Your name"
Next, run the below to set up your email address:
git config --global user.email "you@email.com"
All set, now you will initialize a folder that will hold all the source files for AOSP and also the tracked history of those source files.
Ready to jump in? Then move to the next section!
Initializing the Source Folder
Then, in /home/aosp, create a new folder named source to hold the sources. Switch your current path to /home/aosp/source, then run the following command:
repo init -u https://android.googlesource.com/platform/manifest
Here, init
installs Repo in the current directory. It also initializes a .repo folder, which contains information about the Git repositories that the manifest points to. You pass URL information with -u
param, in this case passing in the URL for AOSP manifest file. This is how Repo gets information from the master branch.
Get an overview of all the branches by visiting the Android source code tags and builds site. In this tutorial, you’ll use the master branch.
-b
argument, as in the example below:
repo init -u https://android.googlesource.com/platform/manifest -b android-10.0.0_r33
repo init -u https://android.googlesource.com/platform/manifest -b android-10.0.0_r33
Once the previous command finishes, check that you’ve successfully set up Repo by running this command again:
repo help
This time, this command shows the following screen:
This is a list of the different commands available with Repo. Check that you get the same output in your terminal.
For more information about Repo’s different options, visit the Repo Command Reference site.
Downloading the Source
Finally, run the following command to download the AOSP source tree to the working directory. Make sure you have a reliable Internet connection and enough space on your drive. Since this process could take between one to two hours, it would be really annoying having to restart it!
repo sync
While you’re waiting is a perfect time to prepare a tasty cup of tea. :]
After a successful sync, your working directory will contain the folders shown below:
Now that you have everything in place, it’s time to actually build the AOSP.
Building the AOSP
The first step to build the AOSP based on the sources you just downloaded is to set up the build environment. Run this command from /home/aosp/source:
source build/envsetup.sh
This will make a set of useful commands — which you’ll need for the next steps — available in your terminal.
Then, type lunch
in your terminal and execute it. This command shows the list of target device types that you can build.
The default option is aosp_arm-eng, which builds the Android images for a device of type phone using the ARM architecture.
You could build this, but when you run the emulator on your computer, you’ll notice that it’s very slow. A better option is to build the target aosp_x86_64-eng.
Select this target by entering the associated index from the list of options. In this case, enter 23 and press Return. The terminal will show the following output:
Running the Build
At this point, the environment is ready to trigger the build. To do so, type m and press Enter. This starts the build process, which takes between two and three hours, depending on your computer.
Are you ready for a second cup of tea? :]
Once the build process completes, you’ll find the result in /home/aosp/source/out/target/product.
To start the emulator, simply execute emulator
. This command is only available because you executed source build/envsetup.sh and then selected a build target with lunch
earlier. If you closed the terminal for any reason after the build completed, you’ll need to run those commands again.
Great job, you just built the AOSP for the first time!
However, your quest doesn’t end here. In the next section, you’ll learn how to modify the Android boot animation.
Setting up the Android Bootloader Animation
The Android OS initializes some internal services during the boot phase, just before the System UI loads. Android displays the bootloader animation, also known as the boot animation, during this time.
If you’re interested in digging into C++, the boot animation source lives in frameworks/base/cmds/bootanimation. Here’s how it works: The system tries to load an animation zip file from the following locations, in order:
- /system/media/bootanimation-encrypted.zip, which is used when data encryption is active.
- /system/media/bootanimation.zip.
- /oem/media/bootanimation.zip.
If the system doesn’t find a boot animation file in those paths, it will dynamically generate a default animation.
Looking at the Boot Animation Format
bootanimation.zip follows a specific format. First of all, it’s important to note that it uses the store compression level, which means that it doesn’t compress its content. The boot animation won’t work if the ZIP file uses compression.
Open and unzip bootanimation.zip, which you downloaded with the materials for this tutorial. Inside the unzipped bootanimation folder, you’ll see a file named desc.txt and three folders named part0, part1 and part2. Inside these partX folders, you’ll find several PNG files with ordered names.
Understanding the Components
The PNGs inside bootanimation.zip represent the different frames of your animation.
They’re in three separate folders because this specific animation contains three different parts:
- part0: The animation shows the raywenderlich.com logo increasing in size.
- part1: The logo’s size increases and decreases, pulsing like a heartbeat.
- part2: The logo’s size decreases.
Note that the number of parts depends on the animation’s design.
desc.txt describes the behavior of the animation. The first line defines the general parameters. In this case, the values 720
, 1280
and 30
correspond to width
, height
and fps
:
- width: The animation’s width in pixels.
- height: Height of the animation in pixels.
- fps: Speed of the animation in frames per second.
The remaining lines give information about each part of the animation. They follow the format type
, count
, pause
, and path
, where:
- type: Indicates the kind of animation. p means this part will play until the end of the boot interrupts it. c means it will play unconditionally until it completes. In your animation, all the parts use type c.
- count: Number of times this part will play. 0 means it loops until the boot completes.
- pause: Indicates the number of frames to delay after this part ends.
- path: Name of the directory containing the frames for this part.
There are a few more parameters you could use to tweak the boot animation. Their full description are in the following file, in the AOSP sources: frameworks/base/cmds/bootanimation/FORMAT.md.