[Android Software Development] vsoma:
[NOOB-FRIENDLY] HOW TO BUILD ANDROID FROM SOURCE CODE [2020 EDITION]

Introduction

Hi, my name is Varun, during the times I was building I faced some trouble building, and I thought it would be helpful if I put together a guide that covers every aspect of building. Many roms fundamentally differ so this is a generic guide, but when it comes to modifying device specific files you are going to have to refer to your rom developer or your device tree maintainer.

I see a lot of lead devs referring to older guides on xda, and felt like there should be a good reference thats more recent.

I have heavily depended upon Nathan Chance's Guide which can be found HERE. I feel like this may be a little intimidating for new builders hence this thread. I will slowly upload screenshots here as I find time. But for now this is what I have. You can find my guide HERE. If there are any changes to be made in this thread then it also needs to be changed on gh, so please do comment or make a pr and fix what is requested.

Table of Contents

1) Getting started

2) Prerequisites

3) Understanding the DOC

4) Preparing Linux environment

5) Getting the source

6) Getting device specific files

7) Building

GETTING STARTED

• This guide will help you understand the basics of rom building.

• You must have exprience with linux and terminal

• You must read everything at least once

• If you get stuck at any step, google is your best friend.

If you still struggle, these are places you can get help

1) This thread

2) GitHub

3) Other XDA threads

4) Telegram (Your SOC groups or Android Builders Help)

• Build only if you have time to spare, never rush through the learning stage

• Never think about skipping a step

• If you are planning to modify a ROM, always ask for permission

• If you are planning on including other peoples work in your rom always ask for permission

Prerequisites

• Your system should have at least 8GB RAM and 4 cores (Use Zram for 8gb ram devices)

• Strong internet connection. You will be downloading 50GB+ worth of files

• Ubuntu - this should be installed alongside a primary OS. NOT VM

• Minimum 250GB of free disk space (you can sync 1 ROMs and build for 3 devices at once)

• Git - Read some documentation

• Command Line - get yourself familiar, learn with CodeAcademy

Understanding This Doc

• Notes with background information will be given in italics

•

is used to represent a command that is run from terminal

PREPARING LINUX ENVIRONMENT FOR BUILDING

• Now the you have finished setting up, a special environment is required for building.

• Preparing the environment is as easy as double clicking .exe in Windows or .dmg in MacOS

thanks to developer Akhil N.

• We need to clone his scripts (installer) from his GitHub

NOTE:

A script is a file which contains multiple commands that run sequentially when executed

git clone https://github.com/akhilnarang/scripts

• This should copy the scripts to directory /home/username/scripts

• Cd into the directory called setup

cd scripts/setup

• List out directory

ls

• Find the file that corresponds to our Linux build. Since we are using Ubuntu it will be android_build_env.sh

For other Distros refer to the readme that has also been cloned

• Run the script

. android_build_env.sh

• Setup GitHub using on screen instructions

• Congratulations you set up your computer for building

• Go back the previous dir that you were originally on (/home/username)

cd

NOTE:

cd will always take you to home/username

GETTING THE SOURCE

• This is probably one of the worst steps, you have to wait a while

• GCloud users will be able to download source in 15 minutes

• Other users may have to wait longer (depends on internet connection speed)

• Make a directory for your ROM

mkdir “ROMNAME”

NOTE:

this will make folder in directory home/username/romname

• Cd in and initiate repository, this basically tells your computer where to download source files from.

The repository initiation command can be found on the GitHub page under “manifest” then scroll down to

repo initialisation and copy command

• It should look like

repo init -u git://github.com/crdroidandroid/android.git -b 10.0

HINTS

NOTE:

1) Linux users can paste into terminal using Ctrl + Shift + V

2) Linux users can copy from terminal using Ctrl + Shift + C

3) GCloud users can paste into window using Ctrl + V

4) GCloud users can copy from window simply by highlighting

5) GCloud users using ssh from terminal can just follow terminal commands

• Once repo is initialised, you can begin download using

repo sync -f --force-sync --no-clone-bundle --no-tags -j$(nproc --all)

• Let everything download

GETTING DEVICE SPECIFIC FILES

• As most of you know the kernel acts as the translator between the OS and your actual hardware

• The files mentioned above are android version specific and will only work with that android

version

• The developer for your device aka dt maintainer will have these files on their GitHub and its

usually linked at the end of the op of other rom threads in the source code section

• You have to make sure that the rom version you downloaded matches up

• If the device tree is for an older version then wait until your dev. releases the latest trees, if no

developer is working on your device then it is possible to modify the tree to work with newer

version of android but it may take some effort.

• In case your tree doesnt match with the rom version that you have downloaded, the easiest and best option is

to scrap everything and download the source version that your tree is designed for

• To scrap everything, use

rm -rf “folder containing rom"

• To modify the init command to download an older version you need to pick out the branch you

need (the branch is basically the version the newer version is added to a new branch)

• Change the init command after -b to include desired branch. For example

repo init -b ten to repo init -b seven

• To get the device specific files, we need to fork them to your GitHub.

Find the stuff (kernel vendor device tree hardware) and fork them

NOTE:

Forking basically copies them to your GitHub

• At this point we need to know if we need to modify the device tree as some ROMs don’t require

you to modify it (CrDroid)(LOS)

• Some roms require only partial modifications, this is rom specific so I wont be going too much into detail

• If modification is required follow these steps , otherwise skip to the end of this section

• After forking we need to modify the files we will do this from the browser for ease of

understanding

•There are three files that need modification and they are located your device tree

• Some tree developers may split your device tree into two parts if there is more than one phone

running the same SOC, so keep an eye out for that. (devices that have the same soc are like the op3/op3t and the op7/op7p)

• The files that we need to modify are under your "device codename" device tree, not "device SOC-common" device tree.

• For example; we need to go to "device_samsung_crownlte" tree not "device_samsung_universal9810-common"

• In here the three files that need modification are

1) Android Products.mk

2) lineage.dependencies

3) lineage_"device codename".mk (example:lineage_crownlte.mk)

• First open AndriodProducts.mk Here replace wherever you see lineage with name of ROM in lowercase only.

• Second, open lineage dependencies.mk and rename file to "romname".dependencies (ecample: aim.dependencies)

• Third, open lineage_"codename".mk and rename to "romname"_"codename".mk and replace

lineage with "romname in the code. (Remember,use lowercase)

NOTE:

If you are building an older version of android make sure you branch out the right branch for your trees

People who do not need to modify can join us here

• Now that all your files are in your GitHub, we need to download them

• There are two easy ways

1) Fast and easy Room Service

2) Slow and boring manual cloning

• Room Service

1) cd into .repo from romsource

cd .repo

2) Make directory local_manifests

mkdir local_manifests

3) Make room service file

nano roomservice.xml

(follow next bullet point on how to make roomservice.xml)

4) Return to ROM folder

cd && cd "romfolder"

• Making the roomservice.xml is as easy as copy paste.

Visit

https://github.com/vrnsoma/local_manifests/blob/lineage-17.1/roomservice.xml

and copy and paste it into a text editor and edit it then paste it into the terminal window (step 3 in above point)

Hint for Device Tree

Example: link= userabc/repositories/device_samsung/crownlte (location on github)

path= device/samsung/crownlte (Where it should download to)

remote= github (where files are stored)

revision= branchname (which version you want)

• Resync Repo like I mentioned before

repo sync -f --force-sync --no-clone-bundle --no-tags -j$(nproc --all)

BUILDING

• Run

. build/envsetup.sh

• Then

brunch codename

• Make sure to clean build by running this in between builds

make clobber && make clean

• If you are using a slow system and want to improve build speeds, use the following command

for making partially clean builds for incremental updates

make installclean

• Building without cleaning is called dirty building and is never advised and do not do this unless

you know what you are doing

KEEPING SETUP UP TO DATE

• Repo sync will keep your rom and device specific files that have been deined in roomservice up to date

CREDITS

NathanChance

All threads on XDA

All guides on Github

All devs found on Telegram

If you want specific credits plz do notify me!

XDA:DevDB Information

BUILDING ANDROID, ROM for all devices (see above for details)

Contributors

vsoma

ROM OS Version: Android 10

ROM Firmware Required: NOOB

Version Information

Status: Stable

Created 2020-10-03

Last Updated 2020-10-03