Table of contents
Android (Android Open Source Project) is an open source mobile operating system which runs the Linux kernel underneath. It is primarily designed for touchscreen mobile devices such as smartphones and tablets. As it's an open source operating system, anyone can build it for any device.
Today we will start with Setting up our Build Environment, sync the AOSP source and then build AOSP.
Setup the Environment
Make sure you are running a Linux Operating System (Ubuntu is preferred). I will be using Ubuntu as an example.
First, we will Install the following packages in our Ubuntu-based system, which will be needed to build AOSP.
sudo apt update &&
sudo apt install -y bc bison build-essential ccache curl flex g++-multilib gcc-multilib git
gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5
libncurses5-dev libsdl1.2-dev libssl-dev libwxgtk3.0-gtk3-dev libxml2 libxml2-utils lzop pngcrush
rsync schedtool squashfs-tools xsltproc zip zlib1g-dev python ssh python2 patchelf binutils
Let's set up our git credentials in our build environment.
git config --global user.email "username@client.com" &&
git config --global user.name "Your Name"
Let's install repo now. Read more about repo over here
mkdir -p ~/.bin &&
PATH="${HOME}/.bin:${PATH}" &&
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo &&
chmod a+rx ~/.bin/repo
Sync the source
As we are done with setting up our build environment for building AOSP, Let's sync the AOSP sources.
First let's make a new folder named aosp using mkdir and navigate into it using cd
mkdir aosp &&
cd aosp
Now we have to initiate the AOSP manifest into the current folder.
repo init -u https://android.googlesource.com/platform/manifest -b BRANCH
Here,
BRANCH -> The AOSP branch you want to sync. It is mostly the Android version and its tag. Suppose you want to sync Android 14 version r45 tag. You have to put android-14.0.0_r45. You can check all the available tags here.
Alternatively, you can add
--depth=1 option before -u in repo init if you don't want the commit history of the source code.
After you have initiated the AOSP manifest, the next step is to sync the source which can be done by a repo command.
repo sync
Alternatively, you can add options with repo sync command. A few commonly used options are:
--force-sync -> This option force syncs the source over the current one and nuke any changes made in the source.
-
jx -> It mentions the number of threads to be used in syncing the source. x signifies the number of threads. Example: -j4 means the sync will use 4 threads.
Building AOSP
If you have followed the following steps, I am sure you have successfully synced the AOSP source code. Now you can build AOSP for your Google Pixel devices or any other device (needs external device trees to be cloned).
After you are done with your device trees, Just follow the steps to start building AOSP.
Initialize the AOSP environment with the envsetup.sh script.
. build/envsetup.sh
or
source build/envsetup.sh
Then we have to lunch the device.
lunch aosp_device-buildtype
Here,
device -> the device codename
buildtype -> the build type:
user for production builds,
userdebug for debuggable builds which are like user type,
eng is solely for debugging and not recommended for production.
Example:
Suppose I want to build for Google Pixel 8 Pro user build, so my lunch command will be:
lunch aosp_husky-ap1a-user
Here,
husky -> The device codename of Pixel 8 Pro
ap1a -> This is the release tag of Android 14 QPR2
user -> Build type
Then, we can finally start compilation of AOSP for our device by running the command:
make otapackage
This will make a flashable AOSP zip for your device. After the compilation is done, you will find your zip in
out/target/product/device_codename directory.