[Android Software/Hacking General [Developers Only]] jai44:
How To Compile Rom From Source

We need following things to compile ROM from source

A Computer( Linux or Mac)

Java JDK

Some required Package for building Rom

Rules for Accessing USB devices

Choosing a Branch

Installing Java on the Machine

Here i am using Ubuntu(14.04 LTS) as a Linux machine but it should work for other Linux variant

Open a terminal and type following

sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*

This command will remove other existing openjdk installation

2. Once java is uninstalled use following command for installing correct version of java

sudo apt-get update

sudo apt-get install openjdk-s8-jdk

Check java version by typing following command

java -version

2. Installing some required packages

Type following in terminal to install some required packages

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

3. Downloading Repo Tool and setting PATH

mkdir ~/bin

curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

chmod a+x ~/bin/repo

Now open the bashrc file and so we can include the repo tool:

sudo nano ~/.bashrc

Add following in the end of the file

export PATH=~/bin:$PATH

Now we need to reload bash variables to include the new path:

source ~/.bashrc

4. Initializing a Repo client

Now we need to create a directory where our source code will be downloaded. I am creating a directory AOSP here

mkdir AOSP

cd AOSP

In the following command insert your name and email address

git config --global user.name "Your_Name"

git config --global user.email "Your_EMail"

Now care fully select your branch whether you are downloading aosp or Cyanogenmod

repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.0_r7

type your desired branch name after the -b. This also applies to Cyanogenmod

5. Downloading source code

Now start downloading source code by typing following

repo sync

Note: this may take some time depending upon your internet speed and also please make sure you have enough storage

6. Configuring USB Access

type your username in following command and type enter

wget -S -O - http://source.android.com/source/51-android.rules | sed "s/<username>/$USER/" | sudo tee >/dev/null /etc/udev/rules.d/51-android.rules; sudo udevadm control --reload-rules

7. Now building Rom for your device

To build rom we need following

Device tree

Vendor tree

kernel

Finding device tree and Vendor Tree

To find your device tree search on Github or similar sources with your device code name. If you are lucky you will find it there and believe me it is the easiest way to build your rom rather than creating device tree and vendor tree from scratch

Your device tree will go on following location

device/device_manufacturer_name/device_codename

Same for vendor tree

vendor/device_manufacturer_name/device_codename

If you find device tree and vendor tree then how to download it

For device tree

git clone “Github url” -b (branch_tag) device/device_manufacturer_name/device_codename

2. For vendor tree

git clone “Github url” -b (branch_tag) vendor/device_manufacturer_name/device_codename

Note1: You may need to change some files if everything is not working or giving you some error in rom compiling. Look into output to find out error. You can use Google if you can't correct it

Note2: You may be not found your device tree and vendor tree then what to do?. You may need to create them. Please follow my guide

Creating Device tree and vendor tree from scratch

For creating device tree

http://azodik.com/how-to-create-device-tree-for-android-rom-building/

2. For creating Vendor tree

“Coming Soon”

Kernel

For kernel part if you are lucky than you can find your kernel source from Github or similar sources. If not you can use your prebuilt kernel Foolow this to extract your kernel http://azodik.com/how-to-create-device-tree-for-android-rom-building/

Kernel location

/kernel/device_manufacturer_name/device_codename

Downloading your kernel

Manually download it and extract to kernel location or use following command

git clone “Github url” kernel/device_manufacturer_name/device_codename

Note1: You can use your prebuilt kernel. To use your prebuilt kernel edit BoardConfig.mk file in your device tree.

Note2: If you created device tree from scratch following my guide. Use of prebuilt kernel set to default

How to build

Use following command for building your rom

Source build/envsetup.sh

lunch

Now select your device from menu

3. make or mka

I hope you found it usefull. Please follow my website for interesting guide. Please comment here if you face any error.

Thank You