Building AOSP (ArrowOS) for my OnePlus 7 Pro
■ Setup directories
■ Setup repo tool
■ Cloning the ROM's manifest repo
■ Sync all the repos in the manifest
■ Setup build env for device
■ Build the ROM
■ Flash the ROM
OnePlus is slow on giving Android updates. So I decided to build an AOSP based ROM with my own patches. ArrowOS is a good place to start. These are some of my notes while building ArrowOS for my OnePlus 7 Pro.
Setup directories
mkdir bin mkdir aosp
bin
is for the tools. For building ROM only the repo
tool is necessary. And aosp
is where the source code is kept.
Setup repo tool
curl https://storage.googleapis.com/git-repo-downloads/repo > bin/repo chmod a+x bin/repo export PATH=$PATH:$(PWD)/bin
This tool helps to bulk clone repositories related to AOSP and device kernel. The repo URLs are described in an XML file called manifest. Every ROM comes with one or a set of manifests. There are local manifests which override the ROM manifests. This is usually where the device specific repos are specified.
Cloning the ROM's manifest repo
I'm using ArrowOS here because it seems to be close to AOSP but at the same time has all the basic things to get started.
cd aosp repo init --depth=1 -u https://github.com/ArrowOS/android_manifest.git -b arrow-12.0
Sync all the repos in the manifest
repo sync -f --force-sync --no-clone-bundle --no-tags -j$(shell nproc --all)
These flags make the sync download least data from the repos. Essentially a shallow clone of the git repos so that older commits are not downloaded. The -j flag, similar to make
, tells to run this in parallel. If a lot of errors show up then change it to -j1 --fail-fast
to show one at a time.
Setup build env for device
I'm compiling AOSP for my OnePlus 7 Pro with codename guacamole
. I also want the Google apps built-in.
export ARROW_GAPPS=true source build/envsetup.sh lunch arrow_guacamole-userdebug
Build the ROM
# To build the OTA ZIP m otapackage -j$(shell nproc --all) # To build the system image m systemimage -j$(shell nproc --all)
This will take some time and disk space. I used a 250GB SSD in an enclosure connected via USB-C to my workstation. Build used almost all of it. If something goes wrong and the errors are not showing up properly check the verbose log like this:
gzip -cd out/verbose.log.gz | less -R
Flash the ROM
For the first flash it is better to use the OTA ZIP file. Because this sets up the file system, partition to boot, cache etc. To flash ZIP, install the recovery image the ROM prefers. Otherwise TWRP will work fine I guess. Then,
adb reboot recovery
# chose ADB sideload from recovery
adb sideload out/target/product/guacamole/arrow_guacamole-something.zip
Afterwards I prefer to use the system image. Because it is faster to build and easy to flash into the device. My development cycle is like this:
# do mods # build system image adb reboot bootloader # if device is already booted fastboot devices # to verify device is detected fastboot flash system out/target/product/guacamole/system.img fastboot reboot