How Include OrangeFox in you build
LeeGarChatHow to Inject OrangeFox Recovery into Your Custom ROM Build (Pixel Devices)
When building custom ROMs for modern Pixel devices (Tensor), integrating a custom recovery like OrangeFox directly into the build process can be tricky.
The Problem: AOSP constraints dictate that BUILDING_VENDOR_BOOT_IMAGE must be true when PRODUCT_BUILD_VENDOR_KERNEL_BOOT_IMAGE is true. Because of this, simply using the standard BOARD_PREBUILT_VENDOR_BOOTIMAGE flag will often conflict or break the build when the system expects to compile vendor_kernel_boot.
The Solution: Instead of rewriting the entire device tree associated with vendor_boot, we allow the AOSP build system (Soong) to compile vendor_boot normally. Then, we inject a custom Make task that overrides the final output recipe. This seamlessly replaces the source-built vendor_boot.img with our prebuilt OrangeFox image right before the target-files and OTA payloads are generated.
Follow these steps to implement the injection method.
Step 1: Download and Place the OrangeFox Image
You do not need to clone the TWRP/OrangeFox device tree. You only need the compiled .img file.
- Download your compiled OrangeFox recovery image.
- Place it in a convenient location within your Android source tree. Example path:
device/google/OrangeFox/Fox.img
Step 2: Edit BoardConfig
You need to declare the prebuilt image in your device's BoardConfig.mk (or BoardConfig-common.mk).
Add the following line to the file, ensuring the path points to where you saved the image in Step 1:
BOARD_PREBUILT_VENDOR_BOOTIMAGE := $(wildcard device/google/OrangeFox/Fox.img)
Step 3: Create the Override Task
Next, we create the .mk file that will override the build recipe. The AOSP build system automatically includes any .mk files located in device/*/build/tasks/, so you do not need to manually import this file anywhere.
- Create a new file at:
device/google/build/tasks/vendor_boot_prebuilt.mk - Add the following code to the file:
# vendor_boot_prebuilt.mk — Use prebuilt vendor_boot.img instead of source-built. # # Solution: Override the vendor_boot BUILD RECIPE itself. Task files are # included after the main Makefile, so this recipe replaces the original # mkbootimg recipe. Prerequisites from the original rule are still merged # (and built), but the recipe body becomes a simple copy operation. # # This way $(INSTALLED_VENDOR_BOOTIMAGE_TARGET) IS the prebuilt from the start, # and everything downstream (target-files, OTA payload) uses the correct image. ifdef INSTALLED_VENDOR_BOOTIMAGE_TARGET $(INSTALLED_VENDOR_BOOTIMAGE_TARGET): device/google/OrangeFox/Fox.img @echo "vendor_boot: using prebuilt device/google/OrangeFox/Fox.img" $(hide) cp device/google/OrangeFox/Fox.img $@ endif
(Note: If you placed your OrangeFox image in a different directory, make sure to update the path in this snippet to match).
How it works
- The build system processes your device tree and compiles the kernel and
vendor_bootfrom source as usual. - At the very end of the Make process, it reads
device/google/build/tasks/vendor_boot_prebuilt.mk. - It sees the override for
$(INSTALLED_VENDOR_BOOTIMAGE_TARGET). - Instead of packaging the newly compiled
vendor_boot, it silently copies yourFox.imgover it. - The final ROM
.zipand OTA payload are generated using the OrangeFox image.