Building an Android ROM from source means downloading the Android Open Source Project (AOSP) tree, compiling it on a Linux machine, and flashing the resulting images to a compatible device. The key condition is compatibility: a stock AOSP build boots on very few retail phones without device-specific board support. You need either a supported development device (Pixel phones are the standard target), a device tree maintained by your device's community, or an emulator for a first successful build.
The rest is deliberately mechanical. Google's build system handles dependency resolution, and the repo tool stitches together roughly a thousand Git repositories into one workspace. What trips people up is hardware, disk space, branch selection, and the gap between "it compiled" and "it boots."
What You're Actually Building, and What You're Not
AOSP is the open-source core of Android: the framework, system services, HALs, the default apps, and the build system. It is not Google Mobile Services, so a pure AOSP image ships without Play Store, Google Play Services, or most of the apps people associate with Android. It's also not a device manufacturer's firmware. Samsung's One UI, Xiaomi's HyperOS, and similar skins contain proprietary drivers and apps that are not in AOSP and cannot be rebuilt from it.
That distinction drives the two common goals. One is building a clean AOSP image for a supported reference device or the emulator, which is the standard learning path and what Google's documentation targets. The other is building a custom ROM for a specific phone — LineageOS, for example — which means starting from a device tree, kernel sources, and vendor blobs that the maintainers publish separately. The second path is more satisfying and considerably more fragile.
A practical note on where the source lives: as of 2026, AOSP publishes source in Q2 and Q4 to match the trunk-stable model, and the android-latest-release manifest branch always points at the most recent release pushed to AOSP. If you're following along with Google's own instructions, that branch is the one they tell you to use.
Prerequisites: Hardware, OS, and Disk Space
Before running a single command, confirm the machine can survive the job. AOSP builds are heavy: a full checkout is well over 100 GB, and build output adds tens of gigabytes more. A 250 GB SSD is a realistic floor, and 400 GB is comfortable. Google's own guidance for the latest release branch specifies a 64-bit Linux host with plenty of RAM — 16 GB is workable, and more helps, especially with parallel jobs.
On the software side, building Android 11 or later requires Ubuntu 18.04 or later. The package list Google publishes for Ubuntu covers the usual suspects: Git, the GCC toolchain pieces, flex and bison, the X11 and GL development headers, libxml2-utils, xsltproc, and font tooling. The current release branch ships prebuilt versions of OpenJDK, Make, and Python 3, so you generally don't need to install those separately — a change from older guides that spent pages wrestling with Java versions.
You'll need repo, Google's wrapper around Git for multi-repository projects. Install it into a directory on your PATH (typically ~/bin) and make it executable. Also set up Git with a name and email, since repo uses them when syncing.
Step 1: Install the Build Dependencies
On a fresh Ubuntu machine, the dependency install is a single command from Google's setup page:
sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig
Run it, then verify Git works and that repo responds to repo --version. If you skip packages here, the failure surfaces much later — usually as a cryptic missing-header error midway through a multi-hour build. Getting this right the first time is the cheapest hour you'll spend.
If you plan to build for a physical device rather than the emulator, install adb and fastboot now too, typically via the Android SDK platform-tools package. You'll need them for unlocking the bootloader and flashing.
Step 2: Download the Source with Repo
Create a working directory (Google's docs use ~/aosp), move into it, and initialize the manifest:
repo init -u -b android-latest-release
The -b flag picks the branch. Using android-latest-release tracks the most recent AOSP release; you can substitute a specific release branch if you need to match a particular Android version for a device tree. Then sync:
repo sync -j8
The -j8 controls parallel fetch jobs; eight is a reasonable default on a decent connection. This step downloads tens of gigabytes and can take anywhere from half an hour to most of a day depending on bandwidth. It's also the step most likely to fail transiently — network hiccups, a briefly unavailable mirror — so if it dies partway, just rerun repo sync and it resumes.
A useful habit: run repo init with the same branch name you'll use later for device trees and vendor blobs. Branch mismatches between AOSP and a community device tree are a leading cause of builds that complete but produce non-booting images.
Step 3: Set Up the Build Environment and Pick a Target
From the root of your checkout, source the environment script:
source build/envsetup.sh
This imports the build commands, including lunch, which selects your build target. Run lunch with no arguments to see the available targets, or supply one directly. For a clean AOSP build on a recent Pixel, the target looks like aosp_-userdebug. For the emulator, targets like aosp_x86_64-userdebug or sdk_phone64_x86_64-userdebug are the usual choices, and they're the safest first target because they need no device hardware.
The build variant matters. userdebug is the standard for development: it includes root access via adb and extensive logging, which you'll want while debugging. user is the locked-down production variant. eng is a kitchen-sink engineering build with extra tools. For a first build, pick userdebug.
Before spending hours compiling, run m or make with a dry-run flag if you want a sanity check that your target resolves. It won't catch everything, but a bad lunch target fails fast, which is preferable to failing after two hours.
Step 4: Compile — and What Success Actually Looks Like
The build itself is one command:
m -j$(nproc)
Or the older make -j$(nproc). The -j value sets parallel jobs; using the core count is a common default, though on memory-constrained machines a lower number prevents out-of-memory kills. On a capable workstation, a first full build of AOSP takes roughly one to four hours. Subsequent incremental builds after small changes are much faster because ccache and the build system reuse prior work — enabling ccache (via export USE_CCACHE=1 and setting a cache size) is worth doing before your first build if you have the disk to spare.
Success is unambiguous: the build prints #### build completed successfully #### and the output images land in out/target/product//. You'll see system.img, boot.img, vendor.img, userdata.img, and similar files. The bootloader images and a flashable set are also generated.
Failure is where the real education happens. The most common causes are a missing dependency package, a lunch target that doesn't exist, mismatched branch between AOSP and a device tree, or insufficient disk or RAM. The error messages are often unhelpful, so the practical check is: does the target resolve? Do the prebuilt kernel and vendor files exist for it? Is out/ filling the disk? Address those before assuming a deeper code problem.
Step 5: Test on the Emulator Before Touching Hardware
Your first successful build should run in the emulator. From the same shell, with the environment sourced and a target lunch'd, the emulator command launches your freshly built image:
emulator
If the emulator doesn't start, verify the sdk_phone64_x86_64 (or similar) target was used and that hardware acceleration (KVM on Linux) is available. Booting your own build in the emulator for the first time is the milestone that proves your toolchain, source sync, and build are all sound — before device-specific variables enter the picture.
Only after an emulator boot should you think about flashing hardware.
The Kernel: A Separate Tree with Its Own Build System
AOSP's tree contains prebuilt kernel binaries, not kernel source. If you want to modify or rebuild the kernel — needed for many device-specific ROMs — you work in a separate kernel checkout, typically initialized with repo against the kernel manifest:
mkdir android-kernel && cd android-kernel repo init -u -b repo sync
Android 13 introduced building kernels with Bazel (the Kleaf system), and recent kernels use it. The build scripts and toolchain come with the kernel sources, so you're not assembling a cross-compiler by hand. Kernel work is a meaningful step up in complexity: branch selection must match your device and AOSP version, and the built boot image has to be integrated back into the system image you flash. For a first ROM, use the kernel that ships with your device tree and skip this until you have a booting build.
Flashing a Physical Device: The Real Constraints
This is where ambition meets reality. Flashing a custom build requires an unlocked bootloader, which on many retail devices voids warranties, wipes user data, and — on some models and in some regions — is not permitted at all. Check your specific device and carrier before buying hardware for this hobby.
The mechanics are straightforward once unlocked: reboot to the bootloader (adb reboot bootloader), then flash the generated images with fastboot — fastboot flash boot boot.img, fastboot flash system system.img, and so on — or use the generated flash-all script if one was produced for your target. Then fastboot reboot.
The failure mode to plan for is the bootloop: the device powers on, the logo appears, and it restarts forever. That usually signals a mismatched vendor image, a kernel that doesn't match the device, or a device tree from a different Android version than your AOSP branch. The recovery path is to reflash a known-good factory image, which is why you should download and verify the factory image for your exact model before you start flashing anything.
Why Most People Should Start from a Device Tree
Building bare AOSP for a retail phone rarely produces a working device because the proprietary drivers, firmware, and hardware abstraction layers aren't in AOSP. Community projects solve this by publishing device trees, kernel sources, and vendor blobs for specific models. The workflow shifts: you sync the ROM project's manifest (which already includes AOSP plus the device tree and vendor repositories), lunch the device-specific target, and build. The same compile command produces images tuned for that phone.
Choosing a device for this matters enormously. Devices with an active maintainer, an unlockable bootloader, and a recent device tree give you a fighting chance. Devices with none of those are a research project, not a first ROM. If you're choosing hardware specifically to learn on, a Pixel with a matching community device tree is the path of least resistance, and it's the device family Google's own kernel documentation uses for examples.
Troubleshooting by Symptom
When something breaks, work backward from the symptom. A sync failure is almost always network or manifest-related — retry, then check the branch name. A lunch failure means the target doesn't exist in your tree, usually because the device tree or vendor repository wasn't synced. A compile failure early in the build points at missing packages or a wrong toolchain; a failure late in the build on a specific module often points at a source mismatch. A build that succeeds but doesn't boot usually means the images don't match the hardware — wrong vendor blobs, wrong kernel, or wrong device tree branch.
Start with reversible checks: confirm the target resolves, confirm the images exist in out/, and confirm the emulator builds and boots. If you escalate to flashing and hit a bootloop, stop and restore the factory image before making further changes — repeatedly flashing mismatched images on top of each other creates confusing states. If the device won't enter fastboot or recovery at all, that's the stop condition; further work needs the manufacturer's service channel or a specialist, not more flashing.
How Long This Takes and What It Costs
The honest time budget: a few hours to set up the machine and sync source, one to four hours for a first build, and a working emulator boot on day one if the dependencies are right. Device-specific work — finding a maintained device tree, matching branches, getting vendor blobs — can stretch to days and depends heavily on how active your device's community is. Hardware costs are the machine (a few hundred dollars for adequate used hardware, more for speed) and the phone itself; the software is free, and the time is the real investment.
None of this requires special credentials or paid tools. It requires a Linux machine with disk and RAM, patience with long builds, and a willingness to read error output carefully. The first successful emulator boot is genuinely achievable in an afternoon on a prepared machine. Everything after that is a matter of matching your build to your hardware — and that's where the difficulty, and most of the learning, lives.