Guide on Building Android Custom ROM
Prerequisites:
- A Linux distribution such as Ubuntu or Arch
- A minimum of 16GB RAM, with an additional 32GB of swap space
- At least 400GB of free storage
- A 6-core CPU (or higher is recommended)
- Device trees for the specific device you will be building
Requirements for Building an Android ROM
To build an Android ROM, you need the following:
- Device Tree
- Kernel Tree
- Vendor Tree
You can find these trees on the LineageOS GitHub repository. Some devices may require additional trees, depending on the model.
Since I am building Evolution X for Google Pixle 7a also known as lynx, I need to modify my device tree to adapt it for this ROM. Here are examples for:
After these modifications, we’re ready to begin building.
Installing Required Packages
For Ubuntu 24.04, use:
sudo apt install git bc bison build-essential ccache curl flex g++-multilib gcc-multilib git git-lfs gnupg gperf imagemagick lib32readline-dev lib32z1-dev libelf-dev liblz4-tool libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev
For Arch-based distros, use:
yay -S git aosp-devel
Setting Up the Build Environment
First, create the necessary directories:
mkdir -p ~/bin
mkdir -p ~/evo
Install the Repo command:
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
Configure Git:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git lfs install
Enable caching to speed up builds:
export USE_CCACHE=1
export CCACHE_EXEC=/usr/bin/ccache
ccache -M 50G
Set the cache size between 30-50GB for building a single device.
Downloading the ROM Source Code
Since we’re building Evolution X, follow the Evolution X sync instructions.
Navigate to the build directory and initialize the repository:
cd ~/evo
repo init -u https://github.com/Evolution-X/manifest -b udc --git-lfs
Sync the repository:
repo sync -c -j$(nproc --all) --force-sync --no-clone-bundle --no-tags
This process may take a few hours, depending on your internet speed.
Preparing Device Trees
For the Pixel 7a (Lynx), here are the trees to clone:
- Main Device Tree: device/google/lynx
- Additional Trees:
- device/google/gs201
- device/google/gs101
- device/google/gs-common
- Prebuilt Kernel: device/google/lynx-kernel
- Vendor Trees: vendor/google/lynx
For each tree, use:
git clone <repository-url> <target-directory>
Example:
git clone https://github.com/razinares/device_google_lynx -b Evolution-X device/google/lynx
Once all trees are cloned in the correct directories, you can start the build.
Building the ROM
Switch to the build environment:
. build/envsetup.sh
Set the build type with lunch
. Evolution X uses the lunch
command (some ROMs use brunch
):
lunch lineage_lynx-userdebug
Where:
lynx
is the device codenameuserdebug
is the build variant
The three build variants:
- user: Suitable for daily usage.
- userdebug: Enables logging features.
- eng: Faster build time, suitable for development. Not recommended for daily use.
Start building Evolution X:
m evolution
The build process may take a few hours. For example, on my Ryzen 3600, it takes about 3 hours.
After a successful build, navigate to the output directory to retrieve the necessary files:
cd $OUT
For flashing, you’ll need:
vendor_boot.img
- Recovery imageEvolutionX-14.0-20241014-lynx-v9.5-Unofficial.zip
If you encounter issues, use adb logcat
to review logs, troubleshoot errors, and resolve any issues.
References:
Happy Building!