46

I'm using gradle 2.9, intellij and Win10 for spring development. In one particular project I encountered this error:

Java home supplied via 'org.gradle.java.home' is invalid. Invalid directory: /usr/local/java/jdk1.8.0_05

Neither solution 1 nor solution 2 work for me.

pitamer
  • 905
  • 3
  • 15
  • 27
roconmachine
  • 1,876
  • 2
  • 17
  • 24

11 Answers11

79

Finally I found my solution. In the project root I found gradle.properties configure this java home

 org.gradle.java.home=/usr/local/java/jdk1.8.0_05

I remove and build it properly.

Igmer Rodriguez
  • 164
  • 4
  • 18
roconmachine
  • 1,876
  • 2
  • 17
  • 24
34
  1. Check the global gradle configuration in C:\Users\<user>\.gradle

  2. In your android project you will have a file named gradle.properties

  3. Delete org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_144

pitamer
  • 905
  • 3
  • 15
  • 27
Warke.shi
  • 349
  • 3
  • 2
  • 1
    the OP has found the solution long back and added a similar answer already – nj2237 Mar 31 '18 at 05:19
  • The accepted answer explicitely asks to look for the properties file in the project root directory. However there are global and local gradle properties and either can be responsible for setting this property value. This one refers to global settings and is in my opinion not the same solution, even though it targets the same attribute. +1 – Koenigsberg Apr 20 '20 at 12:41
  • Helped when adding to `~/.zshrc` instead. – Bishwas Mishra Feb 17 '21 at 18:44
20
  1. In your android project you will have a file name gradle.properties.
  2. Open up that file, there will a line

org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_144

  1. You will have to change this line, insert your jdk setup location, most important use double backslashes "\\" like above in your path.
Atif Mukhtiar
  • 1,186
  • 9
  • 11
3

For anyone on MacBooks, you might want to check if the file in /Users/username/.gradle/gradle.properties has the correct JDK path provided.

I was receiving the following message in Android Studio:

Value '/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home' given for org.gradle.java.home Gradle property is invalid (Java home supplied is invalid)

My gradle.properties file had the following line:

org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home

And I had to change it to the following:

org.gradle.java.home=/Applications/Android Studio 4.1.3.app/Contents/jre/jdk/Contents/Home Since I renamed Android Studio.app to Android Studio 4.1.3.app since I have multiple installations.

ViliusK
  • 11,345
  • 4
  • 67
  • 71
2
  1. If you use visual studio code open folder android\gradle.properties.
  2. Change the path org.gradle.java.home = <local path>\Java\jdk1.8.0_144, e.g. C:\Program Files\Java\jdk1.8.0_191
mechnicov
  • 12,025
  • 4
  • 33
  • 56
2

In my case, I removed this line from my android/gradle.properties:

org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home

And then I edited my android/local.properties and gave the right sdk directory path which can be found in android studio -> preferences -> Appearance & behaviour -> System settings -> Android sdk

Apparently I moved my code from one machine to another so the sdk path was not correct.

salvi shahzad
  • 1,092
  • 12
  • 20
1

Delete this line:

org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home

from gradle.properties. This will work for you.

ouflak
  • 2,458
  • 10
  • 44
  • 49
Ali Panahi
  • 27
  • 1
0

For Mac M1 chip users, add the following line in gradle.properties

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
org.gradle.java.home=/Applications/Android Studio.app/Contents/jbr/Contents/Home //////-ADD THIS LINE ONLY

you can find your java home path

AndroidStudio -> File -> ProjectStructure -> SDKs -> Android studio java home

Java Home Path

Navin Kumar
  • 3,393
  • 3
  • 21
  • 46
0
  1. If you use visual studio code open the folder android\gradle.properties.

  2. Delete This line org.gradle.java.home= C:\Java\jdk1.8.0_361

check screenshot

0

Open android/gradle.properties and check /usr/lib/jvm/java-8-openjdk-amd64 this line available or not. If available, then comment out/remove this line and try to run.

This works for me.

Thank you

Shahadat Hossain
  • 533
  • 7
  • 20
0

After updating to android studio giraffe I changed jre to jbr on M1 mac

org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/Contents/Home/

org.gradle.java.home=/Applications/Android Studio.app/Contents/jbr/Contents/Home/
Firdous nath
  • 1,487
  • 1
  • 14
  • 38