You build the Android SDK from source by syncing a matching AOSP source tree with the repo tool, installing the open-source build dependencies, then running . build/envsetup.sh, lunch sdk-eng, and make sdk (or m sdk) from the tree root. The key condition is version alignment: your host tools, the source branch, and your JDK must all match the same Android release you're building. The old recipe that circulated for years — repo init ... -g all,-notdefault,tools, lunch sdk-eng, make sdk — still describes the shape of the process, but the specific values changed as AOSP's build system evolved. This guide explains the current path and the failure points that actually stop builds.

What "building the SDK from source" actually produces

The SDK itself — platform tools, aapt/aapt2, adb, d8, the android.jar stub library, emulator connectors, and the sdkmanager/avdmanager command-line tools. This is what m sdk assembles. The ADT plugin — the old Eclipse plugin documented in the same historical how-to. It's effectively irrelevant to modern development; Android Studio replaced Eclipse ADT years ago. Skip it unless you're doing archaeology. The Platform Development Kit (PDK) and AOSP images — these are OS builds, not SDK builds. If your goal is "build my own Android system image," that's the AOSP build path (lunch aosp_arm64-eng, m), not m sdk.

Two details matter. First, the installed Android SDK you download via Android Studio is not the same thing as an SDK compiled from source; the latter is a set of build outputs under out/. Second, the prebuilt platform SDK from Google (the one in prebuilts/) exists so the system build can compile Java/Kotlin against the public API surface. Building the SDK from scratch is a niche operation — you'd do it to test a change to SDK tooling, to produce a variant toolchain, or to understand how the packaging works — not as a normal developer setup step.

Also note: the Android source does not ship with prebuilt SDK installation packages in the same way it ships prebuilt toolchains. What m sdk produces is a build output (out/host/linux-x86/sdk/… on Linux), not something you drop into ANDROID_HOME and use immediately, although you can point ANDROID_SDK_ROOT at it for some tooling. Expect to dig into out/ for the archive or directory tree.

Prerequisites you can't skip

The build will fail fast if these aren't right, and each failure tends to look cryptic. Check them before syncing.

Host OS and architecture. AOSP builds are supported on Linux (Ubuntu LTS releases are the common choice) and macOS for the relevant release. Windows is not a supported host for a full AOSP build; the historical how-to had a separate Windows section, and that tells you what era it reflects. Native Windows builds of individual SDK tools exist, but not the full tree from repo. Use x86_64 (or arm64 on Apple Silicon where the release supports it) and be prepared for emulator binaries to differ by host arch.

Disk and RAM. AOSP source trees are large, with a full sync commonly measured in the tens of tens-to-over-a-hundred gigabytes depending on branch and whether you use partial clones. Plan for well over 100 GB with room to grow for out/. A build host with at least 16 GB RAM (more for parallel builds) is the practical floor; 64 GB+ makes make sdk dramatically nicer. make sdk is not a light target — it pulls in building many platform components.

repo and Git. Install Git, then install repo. repo is a Python wrapper around Git that manages the hundreds of repositories in the manifest. Create a working directory, run repo init with a manifest URL, and repo sync. The manifest URL is .

Java. The toolchain builds with an OpenJDK. Historically, older releases used JDK 8 or 9; newer releases use more recent JDKs and may ship a prebuilt java under prebuilts/jdk/. The critical rule: use the JDK version the release's own documentation names. A JDK mismatch is one of the most common causes of m sdk aborting. The build log often says exactly which Java it expected; read it, don't guess.

Open-source build dependencies. Ubuntu-family hosts need packages like git, curl, python3, gnupg, flex, bison, build-essential, zip, zlib1g-dev, and various lib*-dev libraries (ncurses, X11, etc.) depending on the release. Your release's "Establishing a Build Environment" page lists the exact set. Missing libncurses/lib32-style packages and missing bc/zip are classic time-wasters. On macOS, Xcode.commandline tools and homebrew packages like gnupg, coreutils, and gsed (you may need to put Homebrew tools on your PATH ahead of BSD versions) are commonly required.

ccache. Optional but practically essential. AOSP supports ccache (or hint tools like espresso/sccache in newer trees) via USE_CCACHE=1 and CCACHE_EXEC/CCACHE_DIR environment variables. Set the cache size generously (ccache -M 50G) and warm it across syncs.

One more: use a branch that exists and a manifest group that includes what m sdk needs. A modern-init command looks like this:

Pick from the list on source.android.com's "Download the Android source" page (e.g., a android-XX.Y.Z_rN tag for a specific release). The historical how-to used -g all,-notdefault,tools; that group filter was a way to get a broad checkout without every optional project. On modern manifests, syncing the default manifest is the supported path; if you do need to drop projects to save space, use repo sync exclusions sparingly and be ready for m sdk to complain about missing modules. --partial-clone and -c (current branch only) save a lot of time and disk for a first build.

Set up the build environment in the right shell

Every AOSP command must run from the root of the sync, in a shell that has sourced the build environment. That's not optional bookkeeping — envsetup.sh defines lunch, m, mm, mmm, hmm, and other wrappers.

Then lunch with an sdk target. In older docs this is:

sdk-eng selects an SDK build variant with engineering settings (debuggable, extra tools, no release signing constraints). It's the right choice for most SDK-from-source work. Newer AOSP trees still recognize sdk-eng as a valid lunch combination; if lunch prints a list, confirm sdk-eng (or the SDK target your branch's AndroidProducts.mk/sdk.mk exposes) is there before proceeding. If lunch says it "can't find product," your manifest group doesn't include the SDK product definitions — resync with the right group or branch.

Note that source build/envsetup.sh and lunch must be done in the same shell session as the build. If you open a new terminal, repeat both. A very common error is running make sdk in a fresh shell where lunch was never invoked; the build then fails with an obscure "no product" or leaves artifacts in the wrong out/ directory.

hmm prints the available commands if you forget them.

The build command that still works

With the environment sourced and sdk-eng lunched, run:

or equivalently:

Both invoke the same build target. make sdk is the canonical form in the historical docs; m sdk is the shorter wrapper defined by envsetup.sh. Nothing in modern trees requires m over make here, but m is idiomatic and respects OUT_DIR conventions. If you want to see what would happen without building, make -n sdk isn't useful at this scale — just check the build log as it runs.

What to expect: the first build is long. The historical doc said "20 minutes to several hours," and that was a small, old tree on 2009-era hardware. A modern tree with an empty ccache on a 16-thread machine can run into the many-hours range, and m sdk pulls in a lot of dependencies outside the SDK itself. With a warm cache and a fully synced tree, incremental SDK builds are much faster. Start the build, watch the beginning of the log for a Java version mismatch or missing package error, and walk away. You can background it and tail:

Success looks like the build ending with a completion message and output appearing under out/. The exact path depends on branch and host arch, but on a Linux x86_64 host it's typically under out/host/linux-x86/sdk/. Look for a directory or archive with sdkmanager/adb/platform tools, and inspect it with find out/host -maxdepth 5 -type d -name 'sdk*'. From there, the archive or tree is your deliverable. Verify at minimum that adb version, sdkmanager --list (or --version), and the packaged android.jar for the target API exist.

Stop condition: if you get repeated Java or clang toolchain errors despite following the release's documented host requirements, stop reverse-engineering and check the exact branch's official build-environment page and the prebuilt JDK it ships. If the tree is corporately modified or the manifest is custom, that's the point to involve the tree's maintainer rather than rebuilding blind.

The failure points that actually stop builds

Most SDK-from-source failures fall into a handful of buckets. Recognizing them early saves hours.

Java mismatch. The build aborts on a Java version check. Fix: install and point to the JDK the release documents, usually via JAVA_HOME. Don't force newer JDKs because they're "better." Missing host packages. libncurses5-dev, libncursesw5-dev, zip, bc, flex/bison, or 32-bit zlib/X11 libraries. The error names the missing binary or header; install the package the release's host-setup page lists. MacOS case-sensitivity. On the default case-insensitive APFS volume, repo sync can hit file-name collisions. Create a case-sensitive APFS volume and work there — this is a documented requirement, not a workaround. Manifest group missing SDK products. lunch sdk-eng fails to find the product. Fix: resync with the correct manifest group or branch; don't hand-edit AndroidProducts.mk unless you know exactly what the tree expects. Disk exhaustion mid-sync or mid-build. repo sync and out/ are both greedy. df -h before and during. Prune with repo forall -c 'git gc' carefully and delete stale out/ targets you don't need. Stale out/ after a branch switch. Changing branches without repo sync* and a clean out/ gives confusing linker and Java errors. rm -rf out/ (or at least the affected target) and rebuild. Wrong shell state. Fresh terminal without source build/envsetup.sh and lunch. Re-run both. repo protocol/auth glitches. If you're behind a proxy or sync hangs on a specific project, repo sync the single project (or use --fail-fast and re-run) instead of nuking the whole tree.

The one-line principle: when the build complains about a tool, check the release's own "Establishing a Build Environment" page and its prebuilts/ JDK before changing anything else. AOSP trees are self-consistent when you match the documented host to the branch; deviation is where most failures originate.

How long, and how heavy

A realistic worked estimate, using reproducible inputs you can check:

repo sync with --partial-clone and -c: hours on a typical connection and disk, faster on a second sync. Check with repo sync completion messages and du -sh ~/aosp. First m sdk with a cold cache: commonly many hours. The build compiles a large chunk of the platform plus SDK tools; on a 16-core host, expect a long tail on single-threaded packaging steps. With warm ccache and unchanged targets: edits to one SDK tool then m sdk should recompile only that module and repackage. Incremental times vary but are dramatically shorter. Disk: budget on the order of 100–200 GB+ for a modern tree plus out/, with more headroom if you keep multiple targets.

These are ranges, not promises, because throughput depends on your core count, disk type, cache warmth, and the branch's size. Measure your own tree with du -sh before and after rather than trusting a fixed number.

When building from source is the wrong tool

The most useful skill here is knowing when not to do this. If you want a working Android development environment, use Android Studio's SDK Manager or the command-line sdkmanager — the prebuilt SDK is signed, tested, and updated. Building the SDK from source is justified when you are changing SDK tooling itself, producing a custom variant, validating a change to aapt2/d8/apkanalyzer behavior, or learning how the pieces fit together. For those, match the branch to the release you're targeting, follow that branch's host-setup page exactly, and treat the historical how-to as background, not gospel. The command sequence is stable; the surrounding details are not.

The old docs/howto_build_SDK.txt remains a useful historical reference — it's in the AOSP tree's platform/sdk and platform/development history — but its 2009–2015 update dates place it firmly before modern build-system changes. Use it to understand the intent (sdk-eng + make sdk), and use the source.android.com download and build pages for the values.

If you're new to this and just need an SDK, skip all of it and download one. If you need a custom SDK, budget a day, verify your JDK against the branch, and let m sdk run.