[Android Software Development] yuweng:
Preface & Credits

Many newbies make mistake by using other DEV's device tree which is normally meant for building ROMs, using it to build TWRP therefore will result in alot of build errors !

Above script can also be use to build TWRP for any Android devices that uses standard Android header, except for Menu 4 which is specifically for MTK devices only. Just edit the script to add support for your device... :good: Updated support for other devices

This project was actually started way back at 2013 & this is the main reason why TWRP doesn't build is bcos of the tedious, confusing & wrong Build Environment setup, it is all so different on so many different linux distros & OSes version, i went on to developed Easy Magic TWRP.... :cool: Now i use Intel device & this script did build a working TWRP for it too.... :laugh:

That's why i strongly recommends BBQLinux for beginners, Thanks to RD codeworkx, i can guarantee that any Build Error is not cause by wrong BE setup as its already built-in on BBQLinux... :good:

The other reason TWRP doesn't boot is bcos of wrong mkbootimg repack arguments, Thanks to RD osm0sis for his awesome unpackbootimg... :good:

Since many newbies are having problems with building TWRP & flooding the TWRP thread here

Which is actually meant for intermediate users, i've offered to share this script when OP decided to open up a new thread here for TWRP flags.... :good:

Credits Updates

Hacker432 for testing & feedbacks on this script, now it uses the ATC folder so that it'll support other languages other than English & TWRP will boot now when build on cm-12.1 base repo... :good:

OP for giving this script a glamour name ATC aka AIO-TWRP-Compiler... :laugh: :highfive: :good:

My TWRP doesn't boot

Try unpack/ repack your stock 3e recovery.img with AIK, push it to your device & if it doesn't boot then obviously your device is not using standard Android header & so does this script will not build a bootable TWRP. Try google your device info on how they did it, Eg. Sony devices uses BOARD_CUSTOM_BOOTIMG_MK for repacking boot & recovery.img & update it accordingly to your BoardConfig.mk

adb shell cat /proc/last_kmsg
[COLOR="Blue"]OR[/COLOR]
adb shell cat /proc/last_kmsg > kmsg.txt

[U][COLOR="blue"]On Android-6.0 Marshmallow[/COLOR][/U]
adb shell cat /sys/fs/pstore/console-ramoops
[COLOR="blue"]OR[/COLOR]
adb shell cat /sys/fs/pstore/console-ramoops > kmsg.txt

Source

Extreme minimal, TWRP require this only one flag TW_THEME := to build or it will error out. You will also need other flags as well, refer to the OP. Some devices won't boot when certain TWRP flag is used or not used bcos its not compatible with your device kernel ! Most legacy device doesn't support TTF & TWRP won't boot so you have to build with TWRP android-5.1 with TW_DISABLE_TTF := true flag

[URL="https://github.com/TeamWin/android_device_kazam_thunder_q45/blob/cm-10.2/BoardConfig.mk#l49"]TW_NO_EXFAT := true[/URL] [COLOR="Red"]<= To disable exfat[/COLOR]
[URL="https://github.com/TeamWin/android_device_kazam_tornado_348/blob/android-4.4/BoardConfig.mk#l50"]TW_NO_EXFAT_FUSE := true[/URL] [COLOR="Red"]<= To disable exfat[/COLOR]
[URL="https://github.com/carliv/device_elephone_p6000/blob/cm-11.0/BoardConfig.mk#l110"]TW_USE_TOOLBOX := true[/URL] [COLOR="red"]<= Using this flag will use toolbox instead of busybox[/COLOR]

Above are some of the flags that can cause TWRP not to boot up. If you are using Part-Source then you need to add additional projects to support these flags as most of them are disabled on the script. Just remove the remarks # from the script for that particular projects. More detail info refer to above post #11 Part-Source.

Refer to the most bottom Bug Report on how to obtain recovery.log, without it nobody is able to help you.

[URL="https://github.com/omnirom/android_bootable_recovery/blob/android-6.0/minuitwrp/Android.mk#l122-l130"]TARGET_RECOVERY_PIXEL_FORMAT := ABGR_8888[/URL]
TARGET_RECOVERY_PIXEL_FORMAT := RGBX_8888
TARGET_RECOVERY_PIXEL_FORMAT := BGRA_8888

The other reason it doesn't boot is that it actually does boot up but the screen is blank ! Try adb shell & it should work on this scenario.

Try different pixel format one at a time, one of them should work.

[URL="https://github.com/omnirom/android_bootable_recovery/blob/android-6.0/minuitwrp/Android.mk#l114-l116"]TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGB_565[/URL]
[URL="https://github.com/omnirom/android_bootable_recovery/blob/android-6.0/minuitwrp/Android.mk#l79"]RECOVERY_GRAPHICS_FORCE_USE_LINELENGTH := true[/URL]
[URL="https://gerrit.omnirom.org/#/c/13948/"]TW_DISABLE_DOUBLE_BUFFERING := true[/URL]

When not setting any pixel format, the default is RGB565 & it should work on most Android devices. You can also try the above when non of them works.

[URL="https://github.com/omnirom/android_bootable_recovery/blob/android-6.0/minuitwrp/Android.mk#L14-L19"]TW_BOARD_CUSTOM_GRAPHICS[/URL]

If your existing device tree uses this & all the above doesn't work then drop by at TWRP IRC channel to get further help.

Source

Miscellaneous Tips

As mentioned many times, most of the time build error is bcos of wrong BE setup, use BBQLinux & you'll get over it. If you have already build on other distro then refer to here on how to use this script or migrate the source code .repo to BBQLinux.

[URL="https://github.com/omnirom/android_bootable_recovery/blob/android-5.1/variables.h#l173"]TARGET_USE_CUSTOM_LUN_FILE_PATH[/URL]
[URL="https://github.com/omnirom/android_bootable_recovery/blob/android-5.1/data.cpp#l828"]TW_BRIGHTNESS_PATH[/URL] [COLOR="blue"]<= If not define, TWRP will look for it [URL="https://github.com/omnirom/android_bootable_recovery/blob/android-5.1/data.cpp#l840-l841"]here[/URL][/COLOR]
[URL="https://github.com/omnirom/android_bootable_recovery/blob/android-5.1/data.cpp#l855"]TW_SECONDARY_BRIGHTNESS_PATH[/URL]
[URL="https://github.com/omnirom/android_bootable_recovery/blob/android-5.1/data.cpp#l1076"]TW_MAX_BRIGHTNESS[/URL] [COLOR="blue"]<= If not define, TWRP will [URL="https://github.com/omnirom/android_bootable_recovery/blob/android-5.1/data.cpp#l56-l58"]set it[/URL][/COLOR]
[URL="https://github.com/omnirom/android_bootable_recovery/blob/android-5.1/data.cpp#l967"]TW_CUSTOM_BATTERY_PATH[/URL] [COLOR="Blue"]<= If not define, TWRP will use [URL="https://github.com/omnirom/android_bootable_recovery/blob/android-5.1/data.cpp#l972"]this[/URL] or [URL="https://github.com/omnirom/android_bootable_recovery/blob/android-5.1/data.cpp#l986"]this[/URL] [/COLOR]
[URL="https://github.com/omnirom/android_bootable_recovery/blob/android-5.1/data.cpp#l937"]TW_CUSTOM_CPU_TEMP_PATH[/URL] [COLOR="blue"]<= if not define, TWRP will use [URL="https://github.com/omnirom/android_bootable_recovery/blob/android-5.1/data.cpp#l942"]this[/URL][/COLOR]

TWRP has everything specified to standard Android path unless when it doesn't work then you'll need to find that out yourself. Do take note that some device doesn't support certain feature such as CPU temperature, battery level, mount USB storage & etc then refer to the OP for flags to disable it.

adb shell su -c "ls -R" > [COLOR="Blue"]myAndroid.txt[/COLOR]

Above command will list out everything on your device.

adb shell su -c cat /sys/class/power_supply/battery/capacity
[COLOR="blue"]88[/COLOR]

Eg. Say the battery capacity doesn't work then look for that path at myAndroid.txt for something that says battery/capacity & specify it at BoardConfig.mk

adb shell cat /sys/class/thermal/thermal_zone0/temp
[COLOR="Blue"]27516[/COLOR]

If CPU temperature doesn't work then look for thermal/temp

adb shell
su
echo 0 > /sys/devices/platform/i2c-gpio.24/i2c-24/24-002c/backlight/lcd-backlight/brightness
echo 255 > /sys/devices/platform/i2c-gpio.24/i2c-24/24-002c/backlight/lcd-backlight/brightness

If brightness doesn't work, look for lcd-backlight/brightness, Eg. above command should be able to change the level of brightness if that is the correct path as indicated at myAndroid.txt.

Sync corruption

git & repo is like a Super Intelligent Source Code Auto-Resume Downloader when working together . . . :good:

You can stop it at any time, restart it back & it will auto-resume. cm repo & source code is located at ~/cm/.repo, omni at ~/omni/.repo it is a hidden folder & to view hidden folder via File Manager, you need to press Ctrl + h

Sometimes you have corruption then repo sync wouldn't work & normally you just need to delete manifests, manifests.git, manifests.xml with a repo init & repo sync then you'll be back to normal.

If still this doesn't solve the problem then delete everything EXCEPT the folder project-objects & projects, both of this is the actual source code folder.

After this a repo init then repo sync & everything will be back to normal, i guarantee, done this many times, no worries . . . :laugh:

Sometimes when you have severe data corruption, above technique will not work then manually cd ~/cm or ~/omni then repo init then repo sync & see what repo & git has to say then follow the on-screen instructions to remove the corrupted projects.

Scroll back up & see what the error was, remove the corrupted project then repo sync. In this case is rm -rf ~/cm/.repo/projects/prebuilts/clang/linux-x86/host/3.5.git

Subsequent sync show above error. rm -rf ~/cm/.repo/project-objects/CyanogenMod/android_external_icu.git

rm -rf ~/cm/.repo/projects/external/jemalloc.git

rm -rf ~/cm/.repo/projects/system/extras/su.git

rm -rf ~/cm/.repo/projects/external/libcxx.git

rm -rf ~/cm/.repo/projects/external/libcxxabi.git

rm -rf ~/cm/.repo/projects/external/libunwind.git

rm -rf ~/cm/.repo/project-objects/CyanogenMod/android_external_busybox.git

And finally all corrupted projects has been removed, subsequent repo sync & all files will be auto-extracted out.

Corrupted .repo folder

i've make a back up of my .repo folder using tar.gz compression years ago & when extracting out, normally will end with data corruptions except if you use lrzip... :good: You will need to manually remove all the text files such as hooks, pre-auto-gc & commit-msg which is supposed to be a symlink files.

After you force overwrite extraction, a repo init & repo sync will end with above message.

You will need to manually delete all the hooks.txt file found at .repo folder

You will need to manually delete all the commit-msg.txt file

You will need to manually delete all the pre-auto-gc.txt file. You might need to repo sync --force-sync many times to overwrite all the corrupted projects & after that, you won't be getting any of these error messages again.

Syncing work tree error

- Doesn't check out all files

This operation must be run in a work tree

Run the below command will give you hint

repo --trace sync -l

Above hints the corrupted projects so remove it => rm -rf /home/yuweng/cm/.repo/projects/frameworks/ex.git

repo sync still it doesn't extract out all the files so you need to run repo --trace sync -l again. Delete the hinted project => rm -rf /home/yuweng/cm/.repo/projects/frameworks/webview.git

When all error has been fixed, a repo sync & all the files will be extracted out correctly

Source

Bug report

Zip & attach the ~/AIO-TWRP-Compiler/compile.log to your post when replying.

Refer to here on how to submit a proper TWRP bug report . . . :good:

How to obtain recovery log

adb pull /tmp/recovery.log -> Attach to your post

At TWRP -> BackUp -> After Backup go to Advanced -> Copy Log to SDCard

Typically you will find the recovery.log at

Typical Internal SdCard

/emmc/TWRP/BACKUPS/ [Your Device Name] / [Backup date] [ro.mediatek.version.release]

/data/media

/data/media/0

or

Typical External SdCard

/sdcard/TWRP/BACKUPS/ [Your Device Name] / [Backup date] [ro.mediatek.version.release]

Attach it to your post.

At TWRP console (Square button at button) -> You can view the log

If TWRP crash when executing certain menu/ function/ feature then you can use My Master Shifu _that gdb technique for debugging & submit the back trace to Teamwin so that they can fix it... :good:

Try IRC channel to get help directly, prepare all required info such as recovery.log, compile.log & android log, refer to here for the best timing . . . :cool:

TWRP FAQ