Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Gradle fails because it does not support the Java version you run

ErrorCould not determine java version from '11.0.2'.

Short answer

Gradle can only run on JDK versions it knows. Each Gradle release supports a range: Java 17 from Gradle 7.3, Java 21 from 8.5, Java 24 from 8.14, Java 25 from 9.1. Either run Gradle on a JDK in range, or raise the wrapper to a version that supports your JDK.

  • Applies to Gradle 7.3 to 9.x, JDK 17, JDK 21, JDK 25
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Compare the two versions side by side: the JDK in the shell and the Gradle in the wrapper.

    java -version
    ./gradlew --version
  2. 2Match what you see, then jump to its fix

    1. 1Could not determine java version from '21...' on a project with an old distributionUrlThe wrapper's Gradle is older than your JDKFix
    2. 2Works in Android Studio but fails in the terminalThe shell uses a newer JDK than the project supportsFix
    3. 3The newest Java is not yet supported to run GradleYou want the newest Java for compiling, not for running GradleFix

What does the error look like?

  • Could not determine java version from '11.0.2'.
  • Could not determine java version from '21.0.1'.
  • Unsupported class file major version 65

Cause 1 of 3

The wrapper's Gradle is older than your JDK

1Check

Gradle's compatibility table: Java 17 needs Gradle 7.3 or later, Java 21 needs 8.5, Java 24 needs 8.14 and Java 25 needs 9.1.0.

grep distributionUrl gradle/wrapper/gradle-wrapper.properties

2Fix

Raise the wrapper to a version that supports your JDK. Run it twice so the JAR updates too.

./gradlew :wrapper --gradle-version 8.14.3
./gradlew :wrapper

3Verify

The version output works on your JDK.

./gradlew --version

Confirmed by docs.gradle.org

Did this fix it?

Cause 2 of 3

The shell uses a newer JDK than the project supports

1Check

Android Studio runs Gradle on the JDK in its settings. A terminal uses JAVA_HOME, or java on PATH, which may be newer.

echo $JAVA_HOME
java -version

2Fix

Point JAVA_HOME at a JDK within the supported range. Android's documentation recommends setting JAVA_HOME and the IDE's Gradle JDK to the same JDK.

export JAVA_HOME=/path/to/jdk-17

3Verify

The terminal now reports the same JDK as the IDE.

./gradlew --version

Confirmed by developer.android.com

Did this fix it?

Cause 3 of 3

You want the newest Java for compiling, not for running Gradle

1Check

Gradle's documentation says a newest Java version may be supported for compilation or testing only. Toolchains let compilation use a different JDK.

grep -rn "toolchain" --include=build.gradle* .

2Fix

Run Gradle on a supported JDK and declare the Java version for compilation as a toolchain.

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

3Verify

Build with Gradle on the supported JDK.

./gradlew build

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Pin JAVA_HOME and the IDE's Gradle JDK to the same JDK, and write it in the README.
  • Check Gradle's compatibility table before installing a new JDK.
  • Set a Java toolchain so results do not depend on which JDK started Gradle.

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

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.