[ASUS ZenFone 8] bnsmb:
There are a lot of web pages about building your own TWRP image in the internet but at least I did not find a HowTo with all necessary instructions and infos in one place.

Therefor I wrote this little HowTo about building a TWRP image for the ASUS Zenfone 8. The instructions in the HowTo can also be used to create TWRP images for other phones supported by TWRP. The HowTo is for a PC running the Linux OS.

Note that this HowTo can only be used for phones that are officially supported by TWRP.

In the end, creating a TWRP image is also quite easy once you know how it works, thanks to the well-done setup of the development environment by the TWRP developer.

Prereqs

The repositories with the manifests for TWRP are here https://github.com/minimal-manifest-twrp and the repositories with the TWRP files and the device trees for the phones supported by TWRP are here: https://github.com/TeamWin . So you need access to github for creating your own TWRP image.

The tool repo is required to maintain the repositories for TWRP; you can download repo from https://gerrit.googlesource.com/git-repo

It's not necessary to install additional tools for creating an TWRP image -- all necessary tools to create the image are in the repositories for TWRP.

Note

To check if there is a repository with the device tree for another phone for TWRP use the search function on the page https://github.com/TeamWin and search for the device ID of the phone.

To search via script use (I006D is the device ID for the ASUS Zenfone 8):

wget "https://api.github.com/search/repositories?q=I006D" -O ./repository_list

Spoiler content hidden.

To get the device ID for a phone execute :

adb shell getprop ro.product.system.device

e,g.

#
# on a PC for a connected ASUS Zenfone 8
#
[xtrnaw7@t15g /data/develop/android/twrp]$ adb shell getprop ro.product.system.device
I006D
[xtrnaw7@t15g /data/develop/android/twrp]$

#
# on the ZUK Z2 Pro
#
z2_row:/ # getprop ro.product.system.device
z2_row
z2_row:/ #

The device ID is required for the lunch command used to copy the repositories with the device trees (see below).

Building the ROM

First copy the necessary repositories for building TWRP to your local machine using these commands:

#
# create a new directory for the repositories (optional)
#
mkdir twrp
cd twrp

# init the local repositories
#
# As of 27.11.2022 the latest version of the TWRP repositories is 12.1 ;
# to download the default repository version you can omit the parameter "-b twrp-12.1"
# As of 27.11.2022 the repositories for TWRP 12.1 use about 45 GB; to save some
# space (about 12 GB) you could add the parameter --depth=1
#
repo init -u https://github.com/minimal-manifest-twrp/platform_manifest_twrp_aosp.git -b twrp-12.1

# sync the repositories (Parameter -j8 = use 8 parallel jobs; adjust this parameter to
# the number of CPU available on your PC)
#
repo sync -c -j8 --force-sync --no-clone-bundle --no-tags

Next add the device dependent repositories for the ASUS Zenfone 8.

The format of the parameter for the lunch command is

twrp_<device_id>-eng

So the parameter for the ASUS Zenfone 8 is twrp_I006D-eng.

#
# init the environment to build the TWRP image
#
. build/envsetup.sh

export ALLOW_MISSING_DEPENDENCIES=true

lunch twrp_I006D-eng

Spoiler content hidden.

And final build the TWRP image

mka bootimage

Spoiler content hidden.

Note:

For devices without A/B devices use mka recoveryimage.

The TWRP image will be created in file boot.img the directory ./out/target/product/I006D e.g.:

[ TWRP Dev - xtrnaw7@t15g /data/develop/android/twrp ] $ ls -ltr out/target/product/I006D/boot.img
-rw-rw-r--. 1 xtrnaw7 xtrnaw7 100663296 Nov 27 12:06 out/target/product/I006D/boot.img
[ TWRP Dev - xtrnaw7@t15g /data/develop/android/twrp ] $

To test the image just boot the phone from the image

adb reboot bootloader
sudo fastboot boot out/target/product/I006D/boot.img

And check if the boot was succesfull:

[ OmniRom 13 Dev - xtrnaw7@t15g /data/develop/android/twrpX ] $ adb shell getprop ro.bootmode
unknown
[ OmniRom 13 Dev - xtrnaw7@t15g /data/develop/android/twrpX ] $

unknown is the expected value here.

Trouble Shooting

On some pages I found a hint that the build scripts require python2 and will not work with python3. But this is most probably not true anymore because building the image with python3 worked without problems.

It's strongly recommended to use separate sessions for compiling OmniROM or TWRP or even different versions of TWRP:

All these build environments define the same commands in the file ./build/envsetup.sh but with different functionality.

As of 27.11.2022 there are only 2 branches in the repository with the manifests for TWRP : version 11 and version 12.1.

If there is no branch for one of these versions in the repositories for the device tree of the phone for which you want to create a TWRP image the lunch command will fail.

The repositories with the manifests for TWRP prior to version 11 can be fetched with this command:

# Minimal manifest for building TWRP for devices shipped with Android 5.1 through Android 9.0
#
repo init -u https://github.com/minimal-manifest-twrp/platform_manifest_twrp_omni.git -b twrp-9.0

Note that the lunch command in the old repositories does work different.

Notes:

The URL to the repository with the device tree for a phone is also on the page for the device on the TWRP device list: https://twrp.me/Devices/

See https://unofficialtwrp.com/build-compile-twrp-recovery for other possible settings for the build

see here for How to add additional files to an TWRP image

XDA Forum thread about compiling TWRP: How to compile TWRP touch recovery