Gradle cannot find the java executable in the configured Java home
The supplied javaHome seems to be invalid. I cannot find the java executable.Short answer
Gradle takes its Java home from a command-line option, then from org.gradle.java.home in gradle.properties, then from JAVA_HOME. If the highest one points to a folder with no bin/java inside, the build fails. Find which setting wins, fix the path to a real JDK folder, or remove the stale setting.
Fix it fast
1Find out which cause you have
Look for every place the Java home is set, in the order Gradle reads them.
grep -rn "org.gradle.java.home" gradle.properties ~/.gradle/gradle.properties echo $JAVA_HOME2Match what you see, then jump to its fix
What does the error look like?
The supplied javaHome seems to be invalid. I cannot find the java executable.Tried location: C:\Program Files\Java\jdk-17\bin\java.exe
Cause 1 of 2
org.gradle.java.home points to a folder that no longer exists
1Check
Gradle's documentation says org.gradle.java.home in gradle.properties sets the Java home for the build and ranks above JAVA_HOME. A JDK that was uninstalled or moved leaves this path dangling.
grep -rn "org.gradle.java.home" gradle.properties ~/.gradle/gradle.properties2Fix
Set it to the real JDK folder, the one that contains bin/java, or delete the line to fall back to JAVA_HOME.
# gradle.properties
org.gradle.java.home=C:/Program Files/Java/jdk-173Verify
Stop old daemons and run a build.
./gradlew --stop
./gradlew --versionConfirmed by docs.gradle.org
Cause 2 of 2
JAVA_HOME points to a wrong folder
1Check
JAVA_HOME names the JDK installation directory for the client VM. Check that the java executable exists inside it.
echo $JAVA_HOME
ls "$JAVA_HOME/bin/java"2Fix
Point JAVA_HOME at an installed JDK folder and open a new terminal so it is picked up. Also check the command-line option -Dorg.gradle.java.home, which beats both.
export JAVA_HOME=/path/to/jdk-173Verify
Gradle starts and reports its JVM.
./gradlew --versionConfirmed by docs.gradle.org
How do I stop it coming back?
- Avoid hard-coding org.gradle.java.home in a file shared with other machines.
- After upgrading or removing a JDK, search gradle.properties files for its old path.
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 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 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