I recently switched over to Manjaro Linux, which is based on Arch, for compiling my builds of Android. I documented everything during the process to get up and running and thought I might as well turn it into a guide, maybe someone would find it useful. One thing to note, this guide will not tell you how to install Manjaro on your system, there’s plenty of information for that available already.

Currently, this post is based on Manjaro 21.x and compiling ScorpionROM v4.x (Android 11). It should work with any custom ROM using AOSP as it’s primary base, however, there are some extra packages required if the ROM you are building is LineageOS, or Lineage based.

NOTE: Every single custom ROM available is originally based on AOSP, even Lineage. The reason Lineage is so popular as a common base is simple: Device Support. They support so many devices that additional code is required in almost every AOSP repository.

Now, let’s dive into the purpose of this guide. Let’s start with the basics, make sure your system is up to date and install yay (yet another yogurt), which is a pacman wrapper to make installing packages easier:

sudo pacman -Syu yay

A lot of the required packages needed to build AOSP are already included with Manjaro, however, you do need a few more. Let’s add them:

yay -S repo gperf wxgtk2 schedtool perl-switch ccache cpio clang ncurses5-compat-libs lib32-ncurses5-compat-libs xxd-standalone --noconfirm

Note the --noconfirm flag, this allows installation of some packages we need from AUR (Arch User Repository) that aren’t available from Manjaro Official repositories. As mentioned before, if you’re trying to build LineageOS, or similar, then you will need some more packages. If not, you can skip this step and move on to the next. To simplify the process, just install the Lineage metapackage from the AUR, which includes everything you need:

yay -S lineageos-devel --noconfirm

If you want to be able to actually flash your build when you are finished, you’re going to need a couple more packages. So let’s get that setup while we’re at it:

yay -S android-sdk-platform-tools android-udev --noconfirm

These last 2 packages are for getting ADB and Fastboot setup on your machine, as well as ensuring proper communication with your device. By using AUR for SDK tools, and Manjaro Official for setting up “udev rules”, everything runs out of the box without additional configurations.

Next, we need to configure git with some global variables, is best to use your own GitHub username and the email that is associated with that account. Make sure to change the username and email address in the example below to your username and email:

git config --global user.name "nepo"
git config --global user.email "nepo@example.com"

Now that everything is installed, it’s time to create a place to do the actual work. This can be setup however you like, for this guide though, we are going to keep it fairly simple. For example, in your Home directory:

mkdir bin && mkdir srx && cd srx

This creates 2 new directories, bin (more on that next) and srx, the working directory, and then finally changes us into our working directory.

Since Android 11 still relies on Python2, we need to create a symlink to our bin directory:

ln -s /usr/bin/python2 ~/bin/python

The first build will take a bit of time, unless you have some top hardware running. In order to speed up later compilations, ccache needs to be setup. While still in your working directory:

ccache -s

This will output your ccache stats and create a config file in the .ccache folder located in your home directory (ie, /home/$USER/.ccache/ccache.conf). The default size of ccache is 5GB, this is a bit low, so we need to change it to a larger value. Depending on your device, or devices, 30GB per device is a good size. The Pixel 3 XL uses 26.2GB, for example. You can adjust the total size of your ccache by issuing the following command in your working directory:

ccache -M 30G

NOTE: If you have limited space, anything you can spare for ccache will improve future builds. You can always adjust the cache size prior to your next build, increase or decrease, without harm to current cached files (unless you make it too small!) by changing the value in the above command.

In the next step, we are going to add some environment variables to our .bashrc file, located in the Home directory. The variables are placed here so we don’t have to enter them every time a build is started.

xed ~/.bashrc

Add the following to the very bottom:

#Android Additions

export PATH=~/bin:$PATH

export USE_CCACHE=1
export PATH=/usr/lib/ccache/bin/:$PATH

Save and exit, then source your .bashrc file:

source ~/.bashrc

The time has come to initialize repo and sync up the source code. In your working directory, should be srx, unless you changed it:

repo init -u https://github.com/ScorpionRom/scorpion_manifest.git -b sr4

Then repo sync:

repo sync -c -j16 --force-sync --no-clone-bundle --no-tags

This could take a while, depending on your internet speed…

…after the repo sync has finished, it’s time to initialize the build environment and build for your device. If you’re building for an officially supported device, then it’s pretty easy. However, if you are building for a device we do not support, then you’ll need to clone your own device/kernel/vendor trees (or use a local manifest) into the source directory. Which this guide does not cover.

We start with initializing the build environment:

source build/envsetup.sh

The output will look something like this:
including vendor/scorpion/vendorsetup.sh
ccache found and CCACHE_EXEC has been set to : /usr/bin/ccache

It’s time for the “lunch menu”:


Output looks like this:

You’re building on Linux

Lunch menu… pick a combo:
1. scorpion_blueline-user
2. scorpion_blueline-userdebug
3. scorpion_bonito-user
4. scorpion_bonito-userdebug
5. scorpion_coral-user
6. scorpion_coral-userdebug
7. scorpion_crosshatch-user
8. scorpion_crosshatch-userdebug
9. scorpion_taimen-user
10. scorpion_taimen-userdebug
11. scorpion_walleye-user
12. scorpion_walleye-userdebug

Which would you like? [aosp_arm-eng]

Simply type in the number for the device you want to build for and press Enter
Our room service script will then fetch the chosen device, find the dependency file and sync all the necessary repos for you (kernel, vendor, etc). When it’s finished, you’re ready to make your flash-able zip.

make -j$( nproc --all ) bacon

Then, just let it run. My setup takes around 2 hours to make first clean build, then around 40 minutes, thereafter, using ccache. Your time will obviously vary, depending on the hardware you are using.

After the build has finished, it’s time to test everything out. While still in your working directory, issue the following command:

cd $OUT

This will move you into your out directory, where everything you just built is located. The first thing to do is make sure you can boot your device. The easiest way to do this is reboot to the bootloader and check your boot image:

fastboot boot boot.img

IF it boots into the OS, you’re in good shape, otherwise something is wrong and needs to be fixed before you actually flash the device. Assuming the device booted up, you now need to again reboot to the bootloader and flash your working boot image, for an A/B device:

fastboot flash boot boot.img --slot all

Or, if the device is A only:

fastboot flash boot boot.img

After the boot image is flashed to the device, you can use the modified AOSP recovery included in our source to sideload the zip file that was created during the build process. Simply reboot the bootloader:

fastboot reboot-bootloader

Then, using the device hardware keys, boot into recovery and choose the Wipe data/factory reset option to wipe the device. This will wipe all of your data so you may want to backup anything important first. After the wipe has finished select: Apply update from ADB

You can now sideload the ROM zip, this will take a couple of minutes:

adb sideload S*.zip

When finished, choose: Reboot system now, and let the ROM do it’s magic for a few minutes while you look at our boot animation…

Hopefully, you found this guide useful and not too complicated to follow. Building Android from source can be a fun hobby, it can also be frustrating sometimes, you just got to stick with it. Before I sign off, I’d like to give a shout out to my friend NYChitman1 from Dirty Unicorns for the input and tips he provided while I was writing this.