Java Runtime only recognizes class file versions up to 52.0
has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0Short answer
Class file 55 is Java 11 and 52 is Java 8. A tool built for Java 11 was started on a Java 8 runtime. Find the JDK that runs Gradle, then change it: the Gradle JDK setting in your IDE, JAVA_HOME in a terminal, or org.gradle.java.home. Android Gradle plugin 8 and newer needs JDK 17.
Fix it fast
1Find out which cause you have
Print the Java version the terminal uses, then the one Gradle itself reports. They can differ from what your IDE uses.
java -version ./gradlew --version2Match what you see, then jump to its fix
- 1
java -version prints 1.8 and the error appears when you run ./gradlew in a terminalThe terminal's JAVA_HOME or PATH points at Java 8Fix - 2
Sync fails inside Android Studio or IntelliJ, while a terminal build of the same project worksThe IDE's Gradle JDK setting is Java 8Fix - 3
Changing JAVA_HOME and the IDE setting makes no differenceorg.gradle.java.home in gradle.properties pins an old JDKFix
- 1
What does the error look like?
has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0Android Gradle plugin requires Java 17 to run. You are currently using Java 11.
Cause 1 of 3
The terminal's JAVA_HOME or PATH points at Java 8
1Check
In a terminal, JAVA_HOME decides which JDK runs the Gradle scripts, and the java on PATH is used if it is not set.
echo $JAVA_HOME
java -version2Fix
Point JAVA_HOME at a newer JDK. AGP 7.0 needs JDK 11 and AGP 8.0 needs JDK 17; Gradle's own table lists Java 11 as the lowest it can run on from version 5.0.
export JAVA_HOME=/path/to/jdk-17
export PATH="$JAVA_HOME/bin:$PATH"3Verify
Gradle reports a JVM of 11 or newer.
./gradlew --versionConfirmed by developer.android.com
Cause 2 of 3
The IDE's Gradle JDK setting is Java 8
1Check
Buttons in Android Studio use the JDK chosen in its Gradle settings, stored as gradleJvm in .idea/gradle.xml, not the terminal's JAVA_HOME.
grep -n "gradleJvm" .idea/gradle.xml2Fix
Open Settings, Build, Execution, Deployment, Build Tools, Gradle, and choose a JDK of 17 or newer in the Gradle JDK drop-down (the bundled jbr-17 is fine for Android projects).
# Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK3Verify
Sync the project again; the error does not return.
./gradlew helpConfirmed by developer.android.com
Cause 3 of 3
org.gradle.java.home in gradle.properties pins an old JDK
1Check
A gradle.properties file in the project or in the Gradle user home can set the JDK for the build process, and it ranks above JAVA_HOME.
grep -n "org.gradle.java.home" gradle.properties ~/.gradle/gradle.properties2Fix
Remove the line, or point it at a newer JDK.
# gradle.properties
org.gradle.java.home=/path/to/jdk-173Verify
Run Gradle and read the JVM line.
./gradlew --versionConfirmed by docs.gradle.org
How do I stop it coming back?
- Keep JAVA_HOME and the IDE's Gradle JDK on the same JDK.
- Check the AGP release notes for the minimum JDK before upgrading the plugin.
- Do not hard-code org.gradle.java.home to a path that only exists on your machine.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Mobile apps
Flutter Android build fails with Unsupported class file major version
Unsupported class file major version 65
The number is the Java version that tried to read a file: 61 is Java 17, 65 is Java 21.
3 causes, each with a fixMobile apps
Android app crashes because the Apache HTTP classes are missing
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;
From Android 9 the Apache HTTP client is no longer on the default classpath, so code or a library that still uses org.apache.http fails at runtime.
2 causes, each with a fixMobile apps
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
Gradle cannot apply the Android application or library plugin
Failed to apply plugin 'com.android.internal.application'.
Gradle loaded the Android Gradle plugin but could not run it.
2 causes, each with a fix