AOSP Foundations
3 min read

Java Versions

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

While the lowest levels of Android are written in C and C++, the entire application framework, the System UI, and all system apps are written in Java and Kotlin. Consequently, the Java Development Kit (JDK) is a critical component of the AOSP build environment.

However, handling Java in AOSP is notoriously strict, and using the wrong version is one of the most common reasons for build failures for beginners.

Historical Java Requirements

The version of Java you need depends entirely on which branch of Android you are attempting to compile. The build system is completely intolerant of mismatched JDK versions.

  • Android 1.5 to Android 2.2: Required Java 5.
  • Android 2.3 to Android 4.4: Required Java 6.
  • Android 5.0 to Android 6.0: Required Java 7.
  • Android 7.0 to Android 8.0: Required Java 8 (specifically OpenJDK 8).

If you are trying to build an older custom ROM for an obsolete device, you must manually install the exact historical OpenJDK version using apt-get and ensure your JAVA_HOME environment variable points to it.

# Example: 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 Modern Solution: Prebuilt OpenJDK

Starting with Android 9 (Pie), Google solved the "wrong Java version" problem permanently.

Just like they do with the Clang compiler and Python, Google now ships a fully pre-compiled version of the OpenJDK directly inside the AOSP source tree.

When you type make or m on a modern AOSP branch (Android 9 through Android 15), the build system completely ignores any version of Java you might have installed on your host Ubuntu machine. Instead, it strictly utilizes the JDK located in the prebuilts directory:

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

Why ship a prebuilt JDK?

  1. Reproducibility: If 10,000 engineers across the world build Android 14, Google wants a mathematical guarantee that the compiled bytecode is identical. Using a locked, prebuilt compiler ensures everyone is using the exact same toolchain, eliminating "it works on my machine" bugs.
  2. Simplicity: It removes the need for developers to manage update-alternatives on Ubuntu or accidentally break their environment by updating their system packages.

OpenJDK vs Oracle JDK

It is worth noting that AOSP relies exclusively on OpenJDK, the open-source implementation of the Java Platform. You should never attempt to use the proprietary Oracle JDK to build AOSP, as it can introduce licensing issues and the build system is strictly not tested against it.

If you are building modern Android today, you do not need to install Java on your Ubuntu host at all. The source tree contains everything you need natively.