How to build custom ROM for your android: chapter one

How to build custom ROM for your android: chapter one
Photo by Daniel Romero / Unsplash

Your device was once maintained by a generous developer for your favorite custom rom but now, sadly it isn't. Maybe the maintainer got new device or does not have time now.

What do you do?

Well, You can start building for yourself. You need to be a little familiar with tools like os git etc. Other than that, it is not really very difficult.

You would, at the least need a server (virtual or physical) with below configuration:

Basic requirements:

Hardware:

  1. A 64-bit x86 system.
  2. Linux OS with GNU C Library (glibc) 2.17 (ex. ubutu 24)
  3. Min 64GB RAM
  4. 400 GB of free disk space
  5. Lots of cores. The more cores you have, the faster it would be built.

Software:

Once you have the hardware ready, now you would also need to install some softwares. For this tutorial, we are going to assume you are using ubuntu.

  1. Git: Open a terminal in your system and execute below command.
sudo apt install git-all
  1. Platform tools: You can download the zip file here. Then extract it:
unzip platform-tools-latest-linux.zip -d ~
  1. Add the adb and fastboot by adding this to your .profile or .zprofile: I use zsh terminal hence I have put in .zprofile
# add Android SDK platform tools to path
if [ -d "$HOME/platform-tools" ] ; then
    PATH="$HOME/platform-tools:$PATH"
fi
  1. Then execute below for the changes to take effect:
source .zprofile
  1. Install the packages needed to build
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 lz4 libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev

If you are using older version of ubuntu or any other operating system, you would have to find equivalent packages and install them.

Install repo:

repo is a tool by google that manages many Git repositories together. It makes it easier to download and develop rom.

Run below command in a terminal.

sudo apt-get install repo

Now you are ready for building rom for your device.

I am going to take lineage os as an example.

Go to github and then android repository of lineage: https://github.com/LineageOS/android

Do the steps mentioned in the Getting Started section.

repo init -u https://github.com/LineageOS/android.git -b lineage-22.2 --git-lfs
repo sync

While running repo sync, you can also mention flags. Two important flags are

  1. -c : only fetch the default branch of the repo, making the sync faster
  2. -j{n} : you can mention how many cores you want to use to perform repo sync. nproc --all is a command which can tell you how many cores you have. Do not put all the cores. Leave some for the rest of us as well.

Other important flag is --force-sync but we will learn about this later.

Now go and do something cause this is gonna take long time.

Once sync is complete, now you is the time to create your device tree.


Go to chapter 2 for that.