How to compile LineageOS (Detailed guide)
LineageOS is the most popular custom rom for Android phones. Although the compilation process is simple and there’s is a lot of documentation for each ‘piece’ needed to compile the rom, I noticed that there’s no document for beginners that explains how the pieces are connected so I wrote this.
In this post I explain how to compile LineageOS 14.1 for the Google Nexus 5 and the basic concepts that you need to know for compiling roms, like what is a kernel, what are the vendor blobs, how to get it and what it.
This knowledge will allow you to compile custom roms for any phone that supports LineageOS.
This is the hardware I used for this howto:
- Android Phone: Google Nexus 5
- Computer for compiling: Azure VM Standard D8s v5 (8 vcpus, 32 GiB memory) with an Azure Premium SSD LRS Disk of 512GiB.
- Operating system: Ubuntu Server 20.04 lts.
Install and configure the required tools
First of all you need to install adb (Android Debug bridge) and fastboot. These are tools for developers intended for debugging Android Apps and flash roms.
~~ bash wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip unzip platform-tools-latest-linux.zip -d ~/bin ~~
repo command. It is for downloading Android source code. ~~ bash curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo chmod a+x ~/bin/repo ~~
The source code of Android uses Git as version control system. You must configure an username and an email to download the Android source code. It doesn’t have to be real because you won’t commit to Android code repositories. The next code will do the job:
~~ bash git config –global user.email “firstname.lastname@example.org” git config –global user.name “John Smith” ~~
Optional: Configure ccache. It will accelerate subsequent builds by compiling only the code that has changed since the last build.
To do that add these lines to your
~/.bashrc: ~~ bash export USE_CCACHE=1 export CCACHE_EXEC=/usr/bin/ccache ~~
And set maximum space for the cache. In this example the maximum is 100 gigabytes: ~~ bash ccache -M 100G ~~
Now logout or reboot you computer to apply the changes.