seeb4coding_post_placeholder

Fix React Native Gradle JDK Errors (Use JDK 17)

React Native’s Android build runs on Gradle, and Gradle needs the right Java version. If it picks up the wrong JDK, you’ll see errors like these:

Unsupported class file major version 65

Android Gradle plugin requires Java 17 to run. You are currently using Java 11.

Could not resolve all files for configuration ... incompatible Java version

Short answer: the official React Native setup guide recommends JDK 17, and warns that higher versions may cause problems. “Major version 65” means Gradle is running on Java 21. “Requires Java 17” means it’s running on something older. Either way, point Gradle at JDK 17.

Step 1: Check which Java Gradle is using

# Java on your PATH
java -version

# The JVM Gradle actually uses (look for the "Launcher JVM" / "Daemon JVM" line)
cd android
./gradlew --version          # Windows: gradlew --version

Step 2: Install JDK 17 if you don’t have it

# macOS (Azul Zulu, as recommended in the React Native docs)
brew install --cask zulu@17

# Windows (Chocolatey)
choco install microsoft-openjdk17

# Ubuntu / Debian
sudo apt install openjdk-17-jdk

Step 3: Point Gradle to JDK 17

Option A (recommended): set JAVA_HOME

This fixes every project on your machine at once.

# macOS: add to ~/.zshrc
export JAVA_HOME=$(/usr/libexec/java_home -v 17)

# Linux: add to ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64

On Windows, add a user environment variable named JAVA_HOME with your JDK 17 folder, for example C:\Program Files\Microsoft\jdk-17.0.x, then restart your terminal.

Option B: set it for one project in gradle.properties

Add org.gradle.java.home to android/gradle.properties. On Windows, use double backslashes:

# Windows
org.gradle.java.home=C:\\Program Files\\Java\\jdk-17

# macOS (Zulu)
org.gradle.java.home=/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home

Tip: this path is specific to your computer, so it breaks the build for teammates and CI if you commit it. Put the line in your personal ~/.gradle/gradle.properties (C:\Users\YOU\.gradle\gradle.properties on Windows) instead. Gradle reads that file for every project.

Option C: Android Studio’s Gradle JDK setting

If you build from Android Studio, open Settings → Build, Execution, Deployment → Build Tools → Gradle and set Gradle JDK to JDK 17. This only affects builds started from Android Studio, not npx react-native run-android in your terminal.

Step 4: Restart Gradle and rebuild

Gradle keeps a background daemon running on the old Java. Stop it, then build again:

cd android
./gradlew --stop
./gradlew clean
cd ..
npx react-native run-android

FAQ

Can I use JDK 21 with React Native?
The React Native docs still recommend JDK 17 for Android builds. Newer JDKs can work with recent Gradle versions, but if you hit “Unsupported class file major version”, switch to 17. It’s the safe choice.

I changed JAVA_HOME but Gradle still uses the old version.
Run ./gradlew --stop and open a new terminal. Also check that org.gradle.java.home in a gradle.properties file isn’t overriding it.

Does this affect iOS builds?
No. The JDK is only used for Android.

Leave a Reply