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
Share
You are currently viewing page 3 of 3 of this article. Click here to view the first page.

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:

  1. /system/media/bootanimation-encrypted.zip, which is used when data encryption is active.
  2. /system/media/bootanimation.zip.
  3. /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.

Note: The animation was created using an open source animation tool called Synfig Studio, which is 2D Animation Software. Available for all platforms i.e Linux, Windows, macOS. Checkout its official website to learn more about it.

They’re in three separate folders because this specific animation contains three different parts:

  1. part0: The animation shows the raywenderlich.com logo increasing in size.
  2. part1: The logo’s size increases and decreases, pulsing like a heartbeat.
  3. 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.

Customizing the Boot Animation

To change the boot animation in your AOSP build, you need to use the same target you selected earlier in the lunch menu: aosp_x86_64-eng.

Open aosp_x86_64.mk from /home/aosp/source/build/make/target/product. At the bottom of the file, add the following lines:

# Boot animation
PRODUCT_COPY_FILES += \
    device/generic/x86_64/bootanimation.zip:system/media/bootanimation.zip

This tells the build process to copy your animation file to system/media/bootanimation.zip. This is one of the paths where the boot loader will look for a bootanimation.zip file, as described earlier.

Then, copy bootanimation.zip into /home/aosp/source/device/generic/x86_64/.

In aosp_x86_64.mk, find the line starting with PRODUCT_ARTIFACT_PATH_REQUIREMENT_WHITELIST, then add system/media/bootanimation.zip \ after the last \.

Without this, the build process won’t allow you to copy the ZIP file to system/media. The resulting code should look like this:

PRODUCT_ARTIFACT_PATH_REQUIREMENT_WHITELIST += \
    root/init.zygote32_64.rc \
    root/init.zygote64_32.rc \
    system/media/bootanimation.zip \

Finally, save the file and execute the m command to create a new build with the changes. Don’t worry, the build will take only a few minutes — no tea this time! :]

Once the build is done, open the emulator by running emulator in your terminal. Tadaaa! Your emulator shows now your custom animation while booting.

Custom boot animation showing raywenderlich.com animation

To avoid this situation, the recommended alternative is to create your own product. Your challenge is to create the necessary configuration files and add your product as a new entry to the lunch menu.

Check out the Google documentation for building a product for more information.

Challenge: To add your custom boot animation, you modified the original AOSP sources, which can create conflicts when updating the codebase. Remember, there’s a new Android release every year.

To avoid this situation, the recommended alternative is to create your own product. Your challenge is to create the necessary configuration files and add your product as a new entry to the lunch menu.

Check out the Google documentation for building a product for more information.

Congratulations! You just built your very own Android version. Be proud, this is a quest not everyone has accomplished!

Where to Go From Here?

Download the final project using the Download Materials button at the top or bottom of this tutorial.

In this tutorial, you set up your development environment to build AOSP and you added a small customization by replacing the boot animation. You could now try to design your own animation and include it in your build. Surprise us with your design skills!

What you covered here is just the beginning of the AOSP adventure. There’s a lot to learn when it comes to Android platform development. Check out the official AOSP documentation for more information.

If you’re interested in navigating the AOSP source tree online, use the Android code search tool. This will help you get to know the source tree.

Hopefully, this tutorial supported you in your first steps with AOSP. If you have any questions about what you covered or if you want to show off your own Android customization, please join the discussion below!