APK errors

JDK version mismatch

Error text

Unsupported class file major version 65
Android Gradle plugin requires Java 17 to run. You are currently using Java 11.

Cause

Gradle or the Android Gradle Plugin needs a different JDK. The class file is newer than the Java that runs it, or the other way round.

Step-by-step fix

  1. Run java -version and ./gradlew --version to see which Java is used.
  2. AGP 8 needs JDK 17. In Android Studio set Settings > Build > Gradle > Gradle JDK to 17.
  3. On the command line point JAVA_HOME at the JDK 17 folder.
  4. Put jvmToolchain(17) in the project so everyone gets the same Java.
  5. Run ./gradlew --stop, then build again.

Example commands

java -version
./gradlew --version
# gradle.properties
org.gradle.java.home=/usr/lib/jvm/java-17-openjdk-amd64
# app/build.gradle.kts
compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 }
kotlin { jvmToolchain(17) }

How to prevent it

Write the JDK version in the README and in jvmToolchain, in one place.

Author and license: Nibras Code