AOSP Build Environment Setup (Step-by-Step) | Android Internals From Scratch Ep 3
Summary
This video details the critical steps and exact configurations needed to set up a Linux build environment for Android 14, specifically for the Raspberry Pi using the Raspberry Vanilla project. It emphasizes the importance of correct tool versions and system specifications, including RAM, storage, and CPU, to avoid lengthy and difficult-to-debug build failures. Key dependencies like build-essential, multi-lib packages, ninja build, and specific Python and Java (OpenJDK 11) versions are highlighted, along with the setup of the repo tool and Git configuration. The guide aims to ensure a smooth build process by verifying every component before proceeding to the source code download.
Key Insights
A properly configured build environment is essential for successful Android compilation.
Missing or incorrect tool versions in the build environment will cause the build to fail, leading to hours of frustrating debugging.
Install multi-lib packages to support 32-bit code compilation on a 64-bit system.
GCC multi-lib and G++ multi-lib are essential because Android 14, while 64-bit, includes some 32-bit vendor libraries. Skipping these will cause the build to fail late in the process.
OpenJDK 11 is required for the Raspberry Vanilla Android 14 build, not OpenJDK 21.
While online sources may suggest OpenJDK 21, the specific Raspberry Vanilla project requires OpenJDK 11. Using the wrong Java version leads to cryptic build errors.
Sections
Introduction and Project Goal
The video demonstrates building Android 14 from scratch for Raspberry Pi.
The video concludes with four generated image files: boot IMG, system IMG, vendor IMG, and a final flashable Raspberry Pi SD card image. The primary focus is on establishing the correct build environment.
A properly configured build environment is essential for successful Android compilation.
Missing or incorrect tool versions in the build environment will cause the build to fail, leading to hours of frustrating debugging.
The exact commands and versions used for the build are provided.
All commands used in the video are available in the description for users to follow precisely.
Why Linux for Android Builds
Linux is required due to Android's reliance on native tools and POSIX system calls.
Android's build system uses Linux-native tools like make, GCC, clang, and bash scripts. The repo tool specifically relies on POSIX system calls and shell features not available on Windows. Google does not officially support Windows builds.
Ubuntu 22.04 LTS is the recommended Linux distribution for building Android.
The video uses Ubuntu 22.04.5 LTS. For Windows users, setting up a Ubuntu virtual machine via VirtualBox or VMware is advised, as the commands will remain identical.
System Requirements for Building
Minimum 16 GB RAM is crucial for a stable and timely Android build process.
Less than 16 GB of RAM can cause the build to crash or take excessively long to complete.
At least 350 GB of free storage is necessary for the Android build.
The initial source code download (sync) requires approximately 250 GB, with the total storage reaching around 350 GB after the build process.
More CPU cores lead to faster build times.
An eight-core CPU can expect build times of 1 to 2 hours. The example system has 442 GB total space, using 345 GB for the build, leaving 75 GB free.
Installing Build Dependencies
Update package lists before installing any new software.
Running `sudo apt update` ensures that the system fetches the latest stable versions of packages, rather than outdated cached ones.
Install core build tools including GCC, G++, and make.
The `build-essential` package installs GCC, G++, and make, which are the fundamental compilers and build utilities required for compiling code.
Install multi-lib packages to support 32-bit code compilation on a 64-bit system.
GCC multi-lib and G++ multi-lib are essential because Android 14, while 64-bit, includes some 32-bit vendor libraries. Skipping these will cause the build to fail late in the process.
Install supporting tools for the build system.
Packages like libxml2, flex, bison, and curl are supporting tools used by the Android build system but are not directly interacted with by the user.
Install Raspberry Pi specific build dependencies.
For the Raspberry Vanilla project, additional packages like `ninja-build` (a fast build engine), `kpartx`, and `dosfstools` (for SD card image assembly) are required.
Install necessary Python packages for the Raspberry Vanilla build.
The build requires specific Python utilities, template engines, and parsers used by native components, which are not needed for standard AOSP builds.
Verify essential tools like GCC, Python, and make are installed.
A quick sanity check confirms that the fundamental tools are available on the system after installation.
Java Version Configuration
OpenJDK 11 is required for the Raspberry Vanilla Android 14 build, not OpenJDK 21.
While online sources may suggest OpenJDK 21, the specific Raspberry Vanilla project requires OpenJDK 11. Using the wrong Java version leads to cryptic build errors.
Install and verify OpenJDK 11.
The video demonstrates installing OpenJDK 11 and checking the installed version. A command is provided to switch the default Java version if multiple are installed.
Java is integral to the Android build infrastructure.
Java and Kotlin code forms the Android framework and apps. Build tools, which are themselves Java programs, convert this code into Android bytecode, making Java a core part of the build process.
Setting Up the Repo Tool and Git
The repo tool manages Android's numerous Git repositories.
Android's source code is distributed across over 800 Git repositories. The repo tool, using a manifest file, synchronizes all these repositories.
Ensure Git identity is configured before initializing repo.
Repo relies on Git. If Git's identity (name and email) is not configured, `repo init` will fail with an unhelpful error. This configuration is local and does not need to match any online account.
Final Verification and Build Output
Verify all setup steps to prevent late-stage build failures.
A comprehensive verification checks that all required tools are installed correctly, with particular attention to the Java version (must be 11) and Git identity.
The build process generates essential Android image files.
Successful setup leads to boot IMG (kernel/RAM disk), system IMG (framework/system apps), vendor IMG (hardware specifics), and the final Raspberry Vanilla SD card image for direct flashing.
Next Steps
The next episode covers initializing repo and syncing the source code.
Future steps involve using `repo init` with the Android 14 manifest, adding the Raspberry Vanilla local manifest, and performing the large `repo sync` (approx. 250 GB).
Ask a Question
*Uses 1 Wisdom coin from your coin balance










![Learn C Programming and OOP with Dr. Chuck [feat. classic book by Kernighan and Ritchie]](https://i.ytimg.com/vi/PaPN51Mm5qQ/hqdefault.jpg)
