How to Build a LineageOS CustomROM for Your Android Device from LineageOS SourceCode?

How to Build a LineageOS CustomROM for Your Android Device from LineageOS SourceCode?

Introduction

                This time, the topic I will talk about is “How to Build a LineageOS CustomROM for Your Android Device from LineageOS SourceCode?” . LineageOS is the most supported device, most popular, and largest Android CustomROM community. Many Android users are familiar with it, and it is the easiest to start building with LineageOS for those who are just starting out. 

                Because the LineageOS team has many developers/contributors, and they have a lot of kernel sources and device trees for many Android devices, and they are constantly updating them. Even if you are not skilled in modifying from source, you can get it ready.  You can search for your phone’s device name under  https://github.com/LineageOS/ .

                Now after reading my guide, you will be able to build other Android CustomROMs as well. All you need to do is get the Android OS SourceCode and some Linux Make Commands. (Example: Android CustomROM Teams – OmniROM, AOSiP, AOKP, AOSP Extended, Dirty Unicorns, ResurrectionRemix and etc…) 

                One thing to note. The Android OS SourceCode’s Filesize is 20GB or more. So, it will be fine if you have a good internet connection. You can build it on either Linux or Mac. I will only show you how to build on Linux. Currently, I am using Ubuntu 17.04. So, I will show you how to build on Ubuntu. The target Android device I will build is Google Nexus 5X.

LineageOS Android Distribution

Information

Project

Support

Requirements

  • You must have a computer running Linux OS.
  • You must have OpenJDK installed.
  • You must have Python 2.7+ installed. (Because Google’s git-repo is written in Python, git-repo will not work without Python installed.)
  • You must be able to use Git.
  • You should also be able to use Google’s git-repo (you can read about git-repo here . Once you’re done, learn about  git-repo commands here .)

git-repo

                git-repo is a tool developed by Google based on Git. It is very useful in Android ROM Development. It is also called [ git-repo – Multiple Repository Tool ] . Its usefulness is to create a Repo, create an xml file in it, link the repos you want, the repos you want to remote, and then use the repo sync command to download multiple Repositories to your local machine in one place. The idea is that you can download multiple Android SourceCode Repositories required to build a ROM from one of the many, without git cloning each one.

Setup Your Environment

Step 1 : OpenJDK Installation

  • First, you need to install OpenJDK on your computer. Open a terminal and type the following commands.

    sudo apt-get update
    sudo apt-get install openjdk-8-jdk
    sudo apt-get install openjdk-8-jre

    When installing OpenJDK, you should note that the OpenJDK version you install will differ depending on the Android version you are building.

  • For Android Nougat to Android Oreo, install OpenJDK 8.
  • For Android Lollipop to Android Marshmallow, install OpenJDK 7.
  • From Android Gingerbread to Android KitKat, install OpenJDK 6. (No one is saying that it won’t build for Android versions below it.)

Step 2 : Python Installation

                The next step is to install Python. Python 2.7 is fine. (Python 3+ is not very compatible with git-repo. So install 2.7.)

sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.7

Step 3 : Build-Tools Installation

                To install the required build-tools, type the following command in Terminal.

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 4 : Git and Repo (git-repo) Installation

  • First, install Git if you haven’t already. (If you already have it installed, you don’t need to do this step again.)

    sudo apt-get install git-core

  • Setting your username and email in Git
  • Format :

    git config –global user.name “Your Name”
    git config –global user.email “[email protected]

  • Example :

    git config –global user.name “zawzaw”
    git config –global user.email “[email protected]

  • You will need to install Google’s git-repo. (The usefulness has already been explained in the Introduction, so I won’t go into it again.)

    mkdir ~/bin
    PATH=~/bin:$PATH
    curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    chmod a+x ~/bin/repo

                Once you have completed all of these steps, the Setup Environment for building a ROM is complete.

Downloading The Sources

  • The repositories required for the entire Android OS will be downloaded from the Android Platform Manifest Repo.
  • What is included in the Android Platform Manifest is that it contains all the necessary Repos for Android OS such as frameworks repos, bootable recovery, kernel trees(for AOSP), device trees(for AOSP), system repos, hardware repos, system packages apps, Prebuilt GCC Toolchains and buildtools, external repos, vendor, tools repos, etc. The file size is also above 20GB. The file size of the original AOSP SourceCode is much larger.
  • LineageOS Main SourceCode – All Repos
  • LineageOS – Android Platform Manifest
  • First, we will create a directory to download the sources.

    mkdir LineageOS-Project

    cd LineageOS-Project

  • I am about to download the LineageOS Source Code.
  • The last character, ‘lineage-15.0’, is the branch name.
  • lineage-15.1(Coming soon…) is for Oreo(8.1.0+) build.
  • lineage-15.0 is for the Oreo(8.0.0) build.
  • If you use cm-14.0, it is for the Nougat(7.0) build.
  • If you are using cm-14.1, it is for Nougat(7.1.1-7.1.2) build.
  • You can build any Android version you like.
  • Those who want to build Android 8.0.0 (Oreo) Version should use the “lineage-15.0” branch.

    repo init -u git://github.com/LineageOS/android.git -b lineage-15.0

  • Those who want to build Android 8.1.0 (Oreo) version should use the “staging/lineage-15.1” branch.

    repo init -u git://github.com/LineageOS/android.git -b staging/lineage-15.1

  • Type the command below to download the sources.

    repo sync

                After that, it’s time to download the sources. The process of downloading the source code will take some time depending on your internet connection.

Building LineageOS

  • Official Documentation: LineageOS Building for Nexus 5X
  • First, I will tell you what you need to prepare before compiling from source.
  • As I mentioned in the introduction, you can find the Kernel Source and Device Tree Repo required for your Android Phone at github.com/LineageOS/. I’ll tell you how to find it. If you know how to give it a name, you’ll be fine.
  • Example for Nexus 5X (The device name of Nexus 5X is called bullhead.)
  • Format : Device Tree

    android_device_manufacturer_devicename

  • Example : Device Tree for Nexus 5X

    android_device_lge_bullhead

  • Format : Kernel Source

    android_kernel_manufacturer_devicename

  • Example: Kernel source for Nexus 5X

    android_kernel_lge_bullhead

  • The first thing you need is your phone’s Device Tree.
  • Where to add the location is under /device under the downloaded Source dir.
  • Format:

    /device/manufacturer/device_name

  • Example for Nexus 5X:

    /device/lge/bullhead

  • There are two types of kernels when building ROMs. Building from Kernel Source and Building from a Prebuilt Kernel. We recommend building from Kernel Source.
  • After that, if you build from Kernel Source, you will need to modify the Device Tree. For example, for Nexus 5X, open /device/lge/bullhead/BoardConfig.mk with a TextEditor and add the following code. (This step is for you to modify it yourself. You don’t need to use LineageOS Source. Their Official Contributors have already done the steps. For devices they support, you don’t need to do this.)

    # Inline Kernel Build
    KERNEL_TOOLCHAIN := $(ANDROID_BUILD_TOP)/prebuilts/gcc/$(HOST_OS)-x86/aarch64/aarch64-linux-android-4.9/bin
    KERNEL_TOOLCHAIN_PREFIX := aarch64-linux-android-
    TARGET_KERNEL_SOURCE := kernel/lge/bullhead
    TARGET_KERNEL_CONFIG := purez_defconfig
    BOARD_KERNEL_IMAGE_NAME := Image.gz-dtb

  • Explanation:

    This step will be easy to follow after reading the first tutorial I wrote called Building-Kernel .

    Line 1 – This is the Toolchain location where the Kernel will be compiled.
    Line 2 – This is the Kernel toolchain prefix of the Toolchain you will use. (If you don’t understand, please read the Kernel Compilation Tutorial.)
    Line 3 – This is the Kernel Source Location where you will build.
    Line 4 – This is the Kernel Configuration for the Kernel Build.
    Line 5 – You must write the exact Kernel Image Name that will be output for your phone.

  • The next step is the Kernel source section. The location to add it is under /kernel under the Source dir.
  • Format:

    /kernel/manufacturer/device_name

  • Example: for Nexus 5X (This location should return the Kernel Source Path in the Device Tree)

    /kernel/lge/bullhead

  • The vendor section. This one should be added under /vendor under the Source dir.
  • Format:

    /vendor/manufacturer/device_name

  • Example: for Nexus 5X

    /vendor/lge/bullhead

Once these are complete, you are ready to build a LineageOS CustomROM.

Final Steps

  • This is the final step. Go to the downloaded Source Dir and open Terminal. Type the following command.

    . build/envsetup.sh

    (OR)

     

    source build/envsetup.sh

  • Then type the command below. ( It is similar to the lunch command in AOSP )
  • Format:

    breakfast <device_name>

  • Example: for Nexus 5X (bullhead)

    breakfast bullhead

    Note: I left out some unnecessary things here. I won’t mention the “ccache” setup to speed up the compilation process time. It will be confusing. Another thing is that the Make Build Commands for each Android CustomROM Team to build their ROMs are different. Because there is a repo called AOSP/platform/build (https://android.googlesource.com/platform/build). It is a build system written with Makefile for the entire OS. If you understand it, you can customize it. You can create Make Build Commands there.

  • I won’t be uploading screenshots again. Same here. You can see them in the AOSP Building Guide .
  • For LineageOS 14.1 and above, you need to configure Jack.

    export ANDROID_JACK_VM_ARGS=”-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4G”

  • The final step is to run the following command to build the ROM (where bullhead will be different depending on your device name).

    croot
    brunch bullhead

  • The output location is as shown below.

    Output – It will be output as a flashablezip under /out/target/product/bullhead/.

                The compilation process time will depend on your computer’s CPU core.

Post Comment

You May Have Missed