• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[GUIDE][NOOB FRIENDLY]How to compile TWRP from source step by step

Search This thread

Hacker432

Senior Member
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.

Code:
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
Code:
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
Code:
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:
Code:
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.

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.
  1. mkdir ~/NameOfTheFolder It's your choice
  2. cd ~/NameOfTheFolder
  3. repo init -u git://github.com/omnirom/android.git -b BRANCH
  4. 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.
  1. mkdir ~/NameOfTheFolder It's your choice
  2. cd ~/NameOfTheFolder
  3. repo init -u git://github.com/CyanogenMod/android.git -b BRANCH
  4. 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 @lj50036 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.
  1. mkdir ~/NameOfTheFolder It's your choice
  2. cd ~/NameOfTheFolder
  3. repo init -u git://github.com/lj50036/platform_manifest_twrp_omni.git -b BRANCH
  4. 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.
  1. mkdir ~/NameOfTheFolder It's your choice
  2. cd ~/NameOfTheFolder
  3. repo init -u git://github.com/lj50036/platform_manifest_twrp_cm.git -b BRANCH
  4. 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 @MSF Jarvis
http://forum.xda-developers.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

H9SdSSe.png

EEIO5fe.png

gfBQQQn.png


Notice: You can use @lj50036 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:
Code:
[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 ;)
 
Last edited:

NepoRood

Recognized Contributor / Retired Forum Moderator
Jan 26, 2016
2,935
3,911
Bugtussle
Some Tips/Tricks...

Being a Windows user most of my life, I've adapted (and picked up from others) some stuff to Linux, it saves a lot of typing in a terminal :p

1) Right Click, Create New Folder
Just as quick as the "mkdir" command, but more Windowsy (<-- I made a new word) and you see immediate results

2) Right Click, Open In Terminal
Click your way through folders, when you get where you want to be, simply right click on an open space, and choose open in terminal. No need to cd ~/all/the/folder/names/to/your/device

Works in the "out" directory too, when pushing your new recovery to the device. No need to type path to recovery, as you're already there ;)

3) Drag and Drop a Bash Script
On your desktop, create a new file, name it "build_recovery", set permissions to make it exacuteable, then use this example inside the file:
Code:
#!/usr/bin/env bash

make clean

. build/envsetup.sh 

lunch cm_X10-eng

mka recoveryimage

Simply drop it on your terminal window and hit enter :good: (can also be used to "mka bacon")

4) Clone Directly into Folder
Using "Tip 2", go to empty folder (folder must be empty), open your terminal then put a . (<-- that's a dot) at the end of your clone URL, example:
Code:
path: /nepo/android/cm12.1/device/TabletExpress/X10
# Open terminal and type/paste:
git clone https://github.com/neporood/device_TabletExpress_X10.git .
This will clone everything from the repo into the empty folder, no need to download and change names

5) Use a Local Manifest
A great guide, full of information, can be found here
NOTE: if using one of the "minimal" manifests in the OP, there's no need for a local manifest

6) Ramdisk Customization
Sometimes when compiling TWRP, you will need some custom and/or stock recovery files in the ramdisk, such as: init.rc, twrp.fstab, and/or some kernel modules (ko files), just to name a few. This is easily done by creating a "recovery/root" directory in your device folder, everything in "root" will be added when you compile.

Example:
path: /nepo/android/cm12.1/device/TabletExpress/X10/recovery/root/etc/twrp.fstab

When you compile, the twrp.fstab file will be inside the "etc" folder of your ramdisk :cool:


Hope this helps other newbies like myself,
Nepo
 
Last edited:

Hacker432

Senior Member
Being a Windows user most of my life, I've adapted (and picked up from others) some stuff to Linux, it saves a lot of typing in a terminal [emoji14]

1) Right Click, Create New Folder
Just as quick as the "mkdir" command, but more Windowsy (<-- I made a new word) and you see immediate results

2) Right Click, Open In Terminal
Click your way through folders, when you get where you want to be, simply right click on an open space, and choose open in terminal. No need to cd ~/all/the/folder/names/to/your/device

Works in the "out" directory too, when pushing your new recovery to the device. No need to type path to recovery, as you're already there ;)

3) Drag and Drop a Bash Script
On your desktop, create a new file, name it "build_recovery", set permissions to make it exacuteable, then use this example inside the file:
Code:
#!/usr/bin/env bash

make clean

. build/envsetup.sh 

lunch cm_X10-eng

mka recoveryimage

Simply drop it on your terminal window and hit enter :good: (can also be used to "mka bacon")

4) Clone Directly into Folder
Using "Tip 2", go to empty folder (folder must be empty), open your terminal then put a . (<-- that's a dot) at the end of your clone URL, example:
Code:
path: /nepo/android/cm12.1/device/TabletExpress/X10
# Open terminal and type/paste:
git clone https://github.com/neporood/device_TabletExpress_X10.git .
This will clone everything from the repo into the empty folder, no need to download and change names

Hope this helps other newbies like myself,
Nepo

Good addition, thanks :)

Sent from my Y550-L01 using Tapatalk
 

Pavlex4

Senior Member
Sep 26, 2014
391
23
Nis
I have problem:
1. I created empty folder and named it twrp
2. I run this command: repo init -u git://github.com/lj50036/platform_manifest_twrp_cm.git -b twrp-13.0
3. I did repo sync -j3
4. I created folder /kernel/samsung/s3ve3g and put kernel source inside it.
5. I create folder /device/samsung/s3ve3g and put device tree inside it.
6. I create folder /device/samsung/s3ve3g and put vendor files inside it.
7. I run this command: . build/envsetup.sh
8.When I run this command I get error: https://postimg.org/image/6f8f5oypt/

I fixed problem by adding this sources to /device/samsung folder:
https://github.com/CyanogenMod/andro...ce_qcom_common
https://github.com/CyanogenMod/andro...ng_qcom-common
https://github.com/MSM8226-Samsung/a...msm8226-common
 
Last edited:

Hacker432

Senior Member
Try use this value in Boardconfig

I am trying to make recoveryimage for multirom.I have problem TW_THEME is not valid: https://postimg.org/image/m33wfg6nb/
Because you're device tree is not adapted for TWRP
Where are TWRP's flags?
Where is the twrp.fstab? TWRP uses its own fstab format
Also, regarding Multirom, I don't see the device name, are you sure you did again source/blabla lunch(enter) then device number?

NOTICE: https://github.com/TeamWin/android_device_samsung_s3ve3g/blob/android-5.1
This could help you a lot
 
Last edited:

Pavlex4

Senior Member
Sep 26, 2014
391
23
Nis

Top Liked Posts

  • There are no posts matching your filters.
  • 38
    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.

    Code:
    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
    Code:
    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
    Code:
    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:
    Code:
    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.

    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.
    1. mkdir ~/NameOfTheFolder It's your choice
    2. cd ~/NameOfTheFolder
    3. repo init -u git://github.com/omnirom/android.git -b BRANCH
    4. 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.
    1. mkdir ~/NameOfTheFolder It's your choice
    2. cd ~/NameOfTheFolder
    3. repo init -u git://github.com/CyanogenMod/android.git -b BRANCH
    4. 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 @lj50036 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.
    1. mkdir ~/NameOfTheFolder It's your choice
    2. cd ~/NameOfTheFolder
    3. repo init -u git://github.com/lj50036/platform_manifest_twrp_omni.git -b BRANCH
    4. 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.
    1. mkdir ~/NameOfTheFolder It's your choice
    2. cd ~/NameOfTheFolder
    3. repo init -u git://github.com/lj50036/platform_manifest_twrp_cm.git -b BRANCH
    4. 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 @MSF Jarvis
    http://forum.xda-developers.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

    H9SdSSe.png

    EEIO5fe.png

    gfBQQQn.png


    Notice: You can use @lj50036 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:
    Code:
    [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 ;)
    7
    Some Tips/Tricks...

    Being a Windows user most of my life, I've adapted (and picked up from others) some stuff to Linux, it saves a lot of typing in a terminal :p

    1) Right Click, Create New Folder
    Just as quick as the "mkdir" command, but more Windowsy (<-- I made a new word) and you see immediate results

    2) Right Click, Open In Terminal
    Click your way through folders, when you get where you want to be, simply right click on an open space, and choose open in terminal. No need to cd ~/all/the/folder/names/to/your/device

    Works in the "out" directory too, when pushing your new recovery to the device. No need to type path to recovery, as you're already there ;)

    3) Drag and Drop a Bash Script
    On your desktop, create a new file, name it "build_recovery", set permissions to make it exacuteable, then use this example inside the file:
    Code:
    #!/usr/bin/env bash
    
    make clean
    
    . build/envsetup.sh 
    
    lunch cm_X10-eng
    
    mka recoveryimage

    Simply drop it on your terminal window and hit enter :good: (can also be used to "mka bacon")

    4) Clone Directly into Folder
    Using "Tip 2", go to empty folder (folder must be empty), open your terminal then put a . (<-- that's a dot) at the end of your clone URL, example:
    Code:
    path: /nepo/android/cm12.1/device/TabletExpress/X10
    # Open terminal and type/paste:
    git clone https://github.com/neporood/device_TabletExpress_X10.git .
    This will clone everything from the repo into the empty folder, no need to download and change names

    5) Use a Local Manifest
    A great guide, full of information, can be found here
    NOTE: if using one of the "minimal" manifests in the OP, there's no need for a local manifest

    6) Ramdisk Customization
    Sometimes when compiling TWRP, you will need some custom and/or stock recovery files in the ramdisk, such as: init.rc, twrp.fstab, and/or some kernel modules (ko files), just to name a few. This is easily done by creating a "recovery/root" directory in your device folder, everything in "root" will be added when you compile.

    Example:
    path: /nepo/android/cm12.1/device/TabletExpress/X10/recovery/root/etc/twrp.fstab

    When you compile, the twrp.fstab file will be inside the "etc" folder of your ramdisk :cool:


    Hope this helps other newbies like myself,
    Nepo
    3
    Just to lend a hand here...

    Here is an example of my local manifest for the omnirom android-6.0 branch that should save about 30Gigs of disk space (since it removes all the projects that are not required to build twrp). This manifest requires an x86_64 build machine.

    https://github.com/syphyr/cm_build_scripts/blob/master/local_manifests/local_manifests_omni_6.0.xml

    Please let me know if you notice that more projects can be removed.
    2
    Being a Windows user most of my life, I've adapted (and picked up from others) some stuff to Linux, it saves a lot of typing in a terminal [emoji14]

    1) Right Click, Create New Folder
    Just as quick as the "mkdir" command, but more Windowsy (<-- I made a new word) and you see immediate results

    2) Right Click, Open In Terminal
    Click your way through folders, when you get where you want to be, simply right click on an open space, and choose open in terminal. No need to cd ~/all/the/folder/names/to/your/device

    Works in the "out" directory too, when pushing your new recovery to the device. No need to type path to recovery, as you're already there ;)

    3) Drag and Drop a Bash Script
    On your desktop, create a new file, name it "build_recovery", set permissions to make it exacuteable, then use this example inside the file:
    Code:
    #!/usr/bin/env bash
    
    make clean
    
    . build/envsetup.sh 
    
    lunch cm_X10-eng
    
    mka recoveryimage

    Simply drop it on your terminal window and hit enter :good: (can also be used to "mka bacon")

    4) Clone Directly into Folder
    Using "Tip 2", go to empty folder (folder must be empty), open your terminal then put a . (<-- that's a dot) at the end of your clone URL, example:
    Code:
    path: /nepo/android/cm12.1/device/TabletExpress/X10
    # Open terminal and type/paste:
    git clone https://github.com/neporood/device_TabletExpress_X10.git .
    This will clone everything from the repo into the empty folder, no need to download and change names

    Hope this helps other newbies like myself,
    Nepo

    Good addition, thanks :)

    Sent from my Y550-L01 using Tapatalk