AndroidHow To's

How to Build a Custom ROM from Android Open Source Project

If you’re familiar with rooting your Android phone or downloading custom ROMs, such as the highly popular CyanogenMod or its successor Lineage OS, you may have wondered – how do people build these ROMs? How much work exactly goes into developing a customized ROM?

This guide will walk you through the basics of developing your own custom Android ROM. It should be noted that this is a massive undertaking – if you have zero experience in coding or fooling around in Linux terminals, you may want to get some knowledge under your belt before diving into this deep-end. But if you have at least a basic idea of those things, I will try to explain things as simply as possible, so you can follow along.

Basically what we’re doing is downloading the raw Android source code (AOSP) and modifying it to our liking. Because there are so many sources to choose from for different devices, this guide will simply reference the master source known as AOSP (Android Open Source Project).

Now the thing about the AOSP is that the pure source code does not include device-specific hardware proprieties. In layman’s terms, hardware like your camera and GPU will not work “out of the box” when developing with the AOSP. In fact, your device will not even boot without these hardware binaries.

If you’re developing for a Google-branded phone (Pixel, Nexus, etc) you can find the hardware binaries directly from Google, and this guide will walk you through obtaining and building them into your ROM. However, if you’re developing a ROM for a brand-name phone (Sony, Samsung, etc)… well, bless your heart, because you’re in for a ride.

Some manufacturers have their own open-source projects or release development tools for would-be developers, whereas other manufacturers keep a tight lid on their proprietary codes. Here’s a brief list of open-source projects from the more popular manufacturers:

Samsung Open Source Release Center
Sony Developer World
Lenovo Support
Huawei Open Source Release Center
Motorola Developers

With that out of the way, let’s continue under the assumption we are building a ROM for the most basic, vanilla Android experience, for a Google Pixel device. With this knowledge under your belt, you’ll be able to branch out on your own and start developing customized versions of specific manufacturer’s ROMs.

Requirements for this Guide:

  • Android Open Source Project
  • Pixel XL phone or an Android emulator for Linux
  • 64-bit Linux Operating System – Ubuntu or Linux Mint are the most newbie-friendly distros, whereas BBQLinux was developed specifically with Android developers in mind.
  • Python
  • A beefy computer (compiling code takes a lot of memory and space!)

Setting Up Your Build Environment

Let’s begin by setting up the Android emulator on your Linux machine. Whether or not you have a Google Pixel XL device, it’s always safest to try your new ROM on an Android emulator before flashing it to your device. My personal favorite is Genymotion, so I’ll walk you through installing that particular emulator. However, you can also check out this guide “Best Android Emulators for Windows in 2017”, as most of them also have Linux compatibility.

Head over to the Genymotion website, register an account, verify it through email, and download the executable to your Linux desktop.

Now open a Linux terminal, and type:

Chmod +x genymotion-xxxxx.bin (replace xxxx with the version number in the filename)
./genymotion-xxxxxx.bin

Press Y to create the Genymotion directory. Now type in the terminal:

cd genymotion && ./genymotion

Now it will ask you to begin the installation process, so just keep clicking Next until you get to the Add Virtual Devices window. Select “Pixel XL” under Device Model option, and then complete the installation. You can test the virtual device out if you want, it will basically be like having a Pixel XL phone on your desktop.

Let’s now set up Python:

$ apt-get install python

Now we need to setup the Java Development Kit on your Linux machine. Open the Linux terminal and type the following commands:

$ sudo apt-get update
$ sudo apt-get install openjdk-8-jdk

Now you will need to configure the Linux system to allow USB device access. Run the following code in the Linux terminal:

This will download the required 51-android.txt file that allows the aforementioned USB device access. Open the .txt file and modify it to include your Linux username, then place the .txt file in the following location: (as the root user). Now plug your device into your computer via USB for the new rules to automatically take effect.

Downloading the Android Source

The AOSP is hosted on Git, so we’re going to use a tool called Repo to communicate with Git.

First we need to setup a /bin folder in your Home directory. Type the following commands into the Linux terminal:

$ mkdir ~/bin
$ PATH=~/bin:$PATH

Now we will download the Repo tool, so type into the Linux terminal:

$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

After Repo is installed, we must now create an empty directory to hold your work files. So type this into the Linux terminal:

$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY

Now we’ll configure Git with your name and email address – use a Gmail address that you check regularly, otherwise you will not be able to use the Gerrit code-review tool.

$ git config –global user.name “Your Name”
$ git config –global user.email
you@gmail.com

Now we’ll tell Repo to pull the latest master manifest of AOSP from Git:

$ repo init -u https://android.googlesource.com/platform/manifest

If done successfully, you’ll receive a message that Repo has been initialized in your working directory. You’ll also find a “.repo” directory inside the client directory. So now we’ll download the Android source tree with:

$ repo sync

Building  the Android Source

This is where the hardware binaries mentioned at the beginning of this guide come into play. Let’s head over to the AOSP drivers page and download the Pixel XL binaries for Android 7.1.0 (NDE63P). You want to download both the vendor image and the hardware components. These come as compressed archives, so extract them to your desktop and run the self-extracting script from the root folder. Choose to install the binaries to the root of the WORKING_DIRECTORY we created earlier.

Now type into your Linux terminal:

$ make clobber
$ source build/envsetup.sh

Now we’ll choose the target to build, so type:

$ lunch aosp_marlin-userdebug
$ setpaths
$ make –j4

There, we have now “built” an Android ROM from source. So let’s test it in the emulator, by typing into the terminal:

$ emulator

So play around in the emulator a bit. As you can see, a purely vanilla Android experience is quite minimal, and this is why manufacturers customize the AOSP to their needs. So you could flash this ROM we just built to your device if you wanted, but without adding any enhancements, a purely vanilla Android experience would be a very boring thing indeed.

So what manufacturers will typically do with the AOSP is fork it, add their own proprietary binaries, customize the UI, add a boot logo, etc. Manufacturer’s basically just paint over the stock Android ROM, and so that will be your next goal as well.

Stay tuned, as the second part of this guide will go through adding fonts, themes, and a boot animation to your ROM!

10 Comments

  1. Hi,
    Thanks for that article – do you know if I can connect webcam (UVC camera) to the emulated machine? I think genymption supports it but I;m not sure.

    Thanks.

  2. Does just running ‘make’ without arguments produce a functional ROM? How many hardware threads are you running in your computer? You could for example try make -j16
    or make -j32.

    Also from the error log it appears ninja: error: unknown target ‘–j4’ is using an endash not a regular – hypen. Try it with just a regular – not the endash

  3. It should work in Genymotion, you need to press CTRL+3 to bring up the camera configuration and then turn the camera button ON.

  4. Hey there! Great guide! When i built mine i was built in the file system of android and not into a zip file…
    Any idea what would cause that?

  5. Hi Eli,

    Can you please describe a bit more? You mean your ROM was not built as a .zip file, and all of its files ended up in a /system folder?

  6. Ah I see, thats normal because we only used the -make command. Try this:
    # first, build the target-files .zip
    % . build/envsetup.sh && lunch tardis-eng
    % mkdir dist_output
    % make dist DIST_DIR=dist_output
    […]
    % ls -l dist_output/*target_files*

    and

    % ./build/tools/releasetools/ota_from_target_files
    dist_output/tardis-target_files.zip ota_update.zip

    You might also want to see from official AOSP documentation: https://source.android.com/devices/tech/ota/sign_builds

  7. Hi Anilesh,

    Unfortunately it seems like people have been hounding Lenovo to release the source code for the Yoga Tab 3 (and other tablets), and Lenovo has not responded. So it seems devices like the Tab 3 8″ are not included in their open source projects. If you hunt around unofficially, you may be able to find the hardware binaries from another source.

Leave a Reply

Your email address will not be published.

Expert Tip

How to Build a Custom ROM from Android Open Source Project

If the issue is with your Computer or a Laptop you should try using Reimage Plus which can scan the repositories and replace corrupt and missing files. This works in most cases, where the issue is originated due to a system corruption. You can download Reimage by clicking the Download button below.

Download Now

I'm not interested

Close