Android Studio or IntelliJ rejects the JDK chosen for Gradle
Invalid Gradle JDK configuration found.Short answer
The IDE could not use the JDK saved for this project's Gradle runs. Either the saved path no longer exists, or the JDK's version does not suit Gradle or the Android Gradle plugin. Open the Gradle settings and pick a JDK that is installed and in range.
Fix it fast
1Find out which cause you have
See which JDK the project has saved and which one the build really starts with.
grep -n gradleJvm .idea/gradle.xml ./gradlew --version2Match what you see, then jump to its fix
- 1
gradleJvm names a JDK you removed, upgraded or that came from another computerThe saved JDK path no longer existsFix - 2
The IDE shows a different JDK from the one you chose, or the path in the message does not existgradle.properties forces a bad JDKFix - 3
Sync fails right after a JDK upgrade, or the plugin asks for Java 17The JDK is outside the range your Gradle and plugin supportFix
- 1
What does the error look like?
Invalid Gradle JDK configuration found.Android Gradle plugin requires Java 17 to run. You are currently using Java 11.
Cause 1 of 3
The saved JDK path no longer exists
1Check
The choice is stored per project in .idea/gradle.xml. A project copied from a colleague or an old machine keeps a name that is missing here.
grep -n gradleJvm .idea/gradle.xml2Fix
Open Settings, then Build, Execution, Deployment, then Build Tools, then Gradle, and pick a Gradle JDK from the list. GRADLE_LOCAL_JAVA_HOME is the recommended macro for new projects.
# Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK3Verify
Sync the project. The warning disappears.
./gradlew helpConfirmed by developer.android.com
Cause 2 of 3
gradle.properties forces a bad JDK
1Check
IntelliJ checks org.gradle.java.home in gradle.properties first, then JAVA_HOME, when it picks the Gradle JVM for an existing project.
grep -rn "org.gradle.java.home" gradle.properties ~/.gradle/gradle.properties
echo $JAVA_HOME2Fix
Point it at a JDK that exists, or delete the line so the IDE setting applies.
# gradle.properties
org.gradle.java.home=/path/to/jdk-173Verify
Restart the Gradle daemon and sync.
./gradlew --stop && ./gradlew helpConfirmed by jetbrains.com
Cause 3 of 3
The JDK is outside the range your Gradle and plugin support
1Check
Gradle 9 runs on Java 17 to 27 and the Android Gradle plugin 9.5 needs JDK 17. A newer JDK also needs a new enough Gradle: Java 25 needs Gradle 9.1.0 or later.
grep distributionUrl gradle/wrapper/gradle-wrapper.properties2Fix
Choose a JDK in range, such as 17 or 21, or raise the wrapper version to one that supports your JDK.
./gradlew wrapper --gradle-version 9.9.13Verify
The JVM line in the version output is in range.
./gradlew --versionConfirmed by docs.gradle.org
How do I stop it coming back?
- Prefer GRADLE_LOCAL_JAVA_HOME or Gradle daemon JVM criteria over an absolute JDK path in shared files.
- Keep .idea/gradle.xml out of version control if it holds machine paths.
- Check the compatibility table before moving to a new JDK.
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
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 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
FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning on FirebaseInstanceId.getInstance().getToken()
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes.
2 causes, each with a fix