[Android Software Development] Hacker432:
Hi guys,

Today because of the continuous requests of help to compile the TWRP on the developers' dedicated thread, I decided to write a guide for those who know very little about Linux and Android development but want to LEARN

Initial requirements:

1)Linux, I suggest Ubuntu 64bit

2)Willpower

3)A brain of course

Chapter 1: Setting up Build Environment

First requirement is Java. The version you need depends on what Android version you want to compile

Open the terminal and type: java -version

From Gingerbred to Kitkat you have to use openjdk 6

For Lollipop and MM you can use openjdk 7 or opendjk8

Notice: for openjdk8 before start the compilation with "make recoveryimage"

Type: export EXPERIMENTAL_USE_JAVA8=true and press enter.

If you have the wrong version type: sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*

Follow the on-scren instructions to remove it.

Now install the jdk you need

For Openjdk 6

Type the following commands:
sudo add-apt-repository ppa:openjdk/ppa
sudo apt-get update && sudo apt-get install openjdk-6-jdk

For Openjdk 7

Type the following commands:
sudo add-apt-repository ppa:openjdk/ppa
sudo apt-get update && sudo apt-get install openjdk-7-jdk

Next requirement are libraries and build tools

Open a fresh terminal prompt, copy and paste this:

sudo apt-get install git ccache automake lzop bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 g++-multilib python-networkx libxml2-utils bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev squashfs-tools pngcrush schedtool dpkg-dev liblz4-tool make optipng

Now let's get a copy of "repo", it is a program that lets you communicate with git servers and download the source code.

1)mkdir ~/bin -This command creates the bin folder that will contain the repo command
2) curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo -This command downloads the repo command in the bin folder
3) chmod a+x ~/bin/repo -Give the repo command right permissions
4)sudo nano ~/.bashrc At the very bottom(Use page down key) add this line: export PATH=~/bin:$PATH
Then press Ctrl+O and Enter to save and Ctrl+X to exit.
After that type: source ~/.bashrc
-With these commands you add repo to .bashrc file that allows you to call the command from every path.

Chapter 2: Repo sync Android sources

At this point you are almost ready to compile whatever you want but first you need Sources.

These are divided in:

-Android base sources

-Device sources

Let's obtain the first one

If you want to compile ROMs such as CyanogenMod you MUST repo sync the entire sources but if you want to compile only the TWRP recovery you CAN sync minimal sources

Full Sources

NOTICE: replace "BRANCH" with the version of android you want

-Omnirom Sources

Available Android branches:

android-6.0

android-5.1

android-5.0

android-4.4

android-4.3

--Open a fresh terminal and type the followng commands.

mkdir ~/NameOfTheFolder It's your choice

cd ~/NameOfTheFolder

repo init -u git://github.com/omnirom/android.git -b BRANCH

repo sync -jN N=numbers of parallel downloads, it depends on your connection Example: repo sync -j2

-CyanogenMod Sources

Available Android branches:

cm-13.0

cm-12.1

cm-12.0

cm-11.0

--Open a fresh terminal and type the followng commands.

mkdir ~/NameOfTheFolder It's your choice

cd ~/NameOfTheFolder

repo init -u git://github.com/CyanogenMod/android.git -b BRANCH

repo sync -jN N=numbers of parallel downloads, it depends on your connection Example: repo sync -j2

Minimal Sources

NOTICE: replace "BRANCH" with the version of android you want

Thanks to [MENTION=5123642]lj50036[/MENTION] for the minimal manifests

-Omnirom Minimal Sources

Available branches:

twrp-6.0

twrp-5.1

twrp-4.4

--Open a fresh terminal and type the followng commands.

mkdir ~/NameOfTheFolder It's your choice

cd ~/NameOfTheFolder

repo init -u git://github.com/lj50036/platform_manifest_twrp_omni.git -b BRANCH

repo sync -jN N=numbers of parallel downloads, it depends on your connection Example: repo sync -j2

-CyanogenMod Minimal Sources

Available branches:

twrp-13.0

twrp-12.1

--Open a fresh terminal and type the followng commands.

mkdir ~/NameOfTheFolder It's your choice

cd ~/NameOfTheFolder

repo init -u git://github.com/lj50036/platform_manifest_twrp_cm.git -b BRANCH

repo sync -jN N=numbers of parallel downloads, it depends on your connection Example: repo sync -j2

The download of the sources will take a bit ^^

Device sources are divided in

1)Kernel

2)Device Tree

3)Vendors

Sorry, I can't help here cause every device has its own sources

For further informations consult this page: https://www.google.it/url?sa=t&rct=..._intro&usg=AFQjCNGBwIUXnLmxTMEb6ltZvbVyzW9ybw it is for CM but it is valid for almost everything.

About TWRP device tree flags this thread is very very useful, thanks to [MENTION=6552280]MSF Jarvis[/MENTION]

http://xdaforums.com/android/software/twrp-flags-boardconfig-mk-t3333970

NOTICE

If you repo synced CyanogenMod Full sources you don't have TWRP sources so go here, select the branch you want and download it.

https://github.com/omnirom/android_bootable_recovery

Extract the archive in /home/username/NameOfTheFolder/bootable

Rename the folder to "recovery-twrp" without quotes ----> Warning: Be sure that in NameOfTheFolder/device/vendor/devicename/Boardconfig.mk there is RECOVERY_VARIANT := twrp

Chapter 3: TWRP compilation

I'm going to use a device as example

Once you had your sources organised as follow:

/home/username/NameOfTheFolder/device/vendor/devicename

/home/username/NameOfTheFolder/kernel/vendor/devicename

/home/username/NameOfTheFolder/vendor/vendor/devicename

[IMG="Device Tree"]http://i.imgur.com/H9SdSSe.png?1[/IMG]

[IMG="Kernel"]http://i.imgur.com/EEIO5fe.png?1[/IMG]

[IMG="Vendor files"]http://i.imgur.com/gfBQQQn.png?1[/IMG]

Notice: You can use [MENTION=5123642]lj50036[/MENTION] minimal device tree to compile TWRP, remember to adapt it to your phone.

https://github.com/lj50036/android_device_vendor_codename

Download and extract it in /home/username/NameOfTheFolder/device/vendor/ them rename the folder to your devicename

Open a fresh terminal and type the following commands:

[LIST=1]
[*]cd ~/NameOfTheFolder
[*]source build/envsetup.sh
[*]lunch
[*]Type the number of your device and press enter. For example in my case the number 16 is my device
[*]mka recoveryimage ---> This command will start the compilation of the recovery.
[/LIST]

I hope I have been clear, Enjoy ;)
​