If you’re somewhat geeky you might get bored by using the same UI on your Android phone and might go Google some ROMs for your device, and guess what? There are no ROMs available! And you have no clue how to make one by yourself, so today I’m writing the tutorial on How To Build Android Custom ROMs from source!
To build Android ROMs you need to be on a Linux machine, I personally use Ubuntu 17.10 but any other Linux distro should work well!
Step 1: Settin up environment.
To get started you should have basic knowledge of Linux terminal.
Now install the following packages:
sudo apt-get install openjdk-8-jdk
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip
Step 2: Configure repo and git:
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
Step 3: Configure git with username & email:
git config –global user.name “username”
git config –global user.email “email”
Step 4: Download the source code of the ROM you want to build:
Just go to the manifest of the ROMs github and you’ll find the command to download source:
repo init -u git://github.com/LineageOS/android.git -b cm-14.1
These are commands to download LineageOS sources:
(sources are around 20GB+ so you’ll need good internet connection and patience)
Step 5: Getting kernel sources, device tree & vendor blobs:
just google for them and clone them in working folder 🙂
I’ll clone OnePlus2’s kernel sources for demo
So, command to code will be:
git clone https://github.com/OnePlusOSS/android_kernel_oneplus_msm8994.git -b 5.1.1 kernel/oneplus/msm8994
-b = branch (you will see it on the git page)
branch is followed by directory ignore the first word after ‘/’ here it is android.
where you see an underscore replace it with slash.
cloning is same for the device tree & vendor blobs as-well.
Now to test if your ROM will compile or not, we use the following commands:
If you see your device listed there like mine will be ‘lineage_oneplus2-userdebug’ then go and enter the number corresponding your device and hit enter, If you can see details about your device then congrats you’re ready to build.
Now enter the build command (may differ with ROMs, refer your ROM’s GitHub)
For lineageOS it is:
So for device OnePlus 2 it will be:
Now the build process will start, this might take time depending upon your PC’s hardware. The ZIP file will be located in the OUT folder inside your working directory.
Done, so this was a brief guide on how to build a ROM from source, if you have any questions or errors put ’em in comments below.