AOSP Foundations
4 min read

Java Versions

Understand the strict Java version requirements across different Android releases and how AOSP handles the JDK.

You clone an Android 8.0 source tree, type the make command, and the build crashes immediately with a cryptically unhelpful compiler error. Your host machine is brand new. Your Ubuntu installation has the latest tools. Yet the Android build system completely refuses to compile the framework code. The reason is a fundamental incompatibility between modern host systems and historical Android branches.

Why the Wrong Java Version Will Break Your Build

The application framework strictly requires Java, creating a massive compatibility constraint. The bytecode generated by the Java compiler must perfectly match the expectations of the Android runtime engine for that specific release. Using a modern Java 11 compiler to build Android 8.0 is like trying to use a new car key in an old ignition. The bytecode simply will not fit into the Dalvik or ART environment expected by the older platform.

To compile historical branches, you must provide the exact version of the Java Development Kit the original developers used. The build system enforces this strict coupling without exception.

Android VersionRequired Java Version
Android 1.5 to 2.2Java 5
Android 2.3 to 4.4Java 6
Android 5.0 to 6.0Java 7
Android 7.0 to 8.0OpenJDK 8

When building a legacy custom ROM today, you have to manually configure your host environment to satisfy these rules. You install the required historical package using the package manager. Then you point your environment variables directly to that specific installation path.

# Setting up a legacy environment for Android 8.0
sudo apt install openjdk-8-jdk
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
java -version

The most common mistake engineers make here is attempting to install the proprietary Oracle JDK instead of OpenJDK. AOSP relies exclusively on OpenJDK, and the build system will fail unexpectedly if it encounters proprietary Oracle binaries.

Managing these host environment variables was a massive headache for thousands of engineers globally. This constant friction led Google to rethink how they distribute the compiler starting with Android 9.

How Google Eliminated "It Works On My Machine"

Imagine ten thousand engineers across the world all building Android 14 on different hardware. Google needs a mathematical guarantee that the compiled bytecode is perfectly identical every single time. Relying on whatever random Java version an engineer happens to have installed on their laptop makes reproducible builds impossible. The platform engineers needed a way to lock the toolchain and force everyone to use the exact same compiler.

The solution is a hermetic build system. Instead of asking you to bring your own tools, modern AOSP ships a locked toolbox inside the source tree itself. When you trigger a build, the system intercepts the process and routes compilation away from your host OS.

This diagram clarifies the shift to a self-contained architecture in three steps. First, it shows the legacy build depending entirely on the host operating system. Second, it depicts the modern source tree containing its own prebuilt tools. Third, it demonstrates how the modern command routes execution directly to the internal directory.

By intercepting the command, the build process locates the prebuilt OpenJDK binary directly. Your host operating system is completely bypassed.

To see this in action, you can inspect the exact custom binary that modern AOSP utilizes. You just navigate to the internal directory and execute the version command.

# Inspecting the prebuilt Java binary used by modern AOSP
./prebuilts/jdk/jdk11/linux-x86/bin/java -version

A common mistake developers make on modern branches is running system updates on their host Java, assuming it will improve compile times. The AOSP toolchain explicitly ignores host variables, making local system updates completely irrelevant to the build process.

Tip: Even if your Ubuntu host has zero JDKs installed, modern AOSP will compile perfectly. The hermetic environment provides everything it needs natively.

Older Android branches force you to manage exact toolchain versions on your host machine. Modern AOSP branches solve this by packing their own compiler directly in the source tree to guarantee identical output everywhere.

Now that the source tree has its own hermetic tools, a different problem emerges. We need an engine capable of orchestrating the compilation of millions of individual source files.