I have tried reinstalling the JDK a few times
reset the JAVA_HOME
I know that the JAVA_HOME needs to be set to C:\Program Files\Java\jdk1.8.0_102
I know PATH has to be set to C:\Program Files\Java\jdk1.8.0_102\bin
I am confused as to why you have to set user variables and system variables
I set both the JAVA_HOME and the PATH in both User vairables and System variables
I have added "C:\Users\*\AppData\Local\Android\sdk\tools" and "C:\Users\*\AppData\Local\Android\sdk\platform-tools" System "Variables/Path"
Here is an Image of most of the settings, I have tried a few things and cant seem to find the problem any help please
Download Liberica JDK and on installation it will automatically set JAVA_HOME environment variable. Now you just go to Android Studio -> Project Structure -> SDK -> Point all jdk path to liberica jdk installation directory and apply. You are done. Just restart android studio and gradle command will work.
Verify JAVA_HOME Enter the command echo %JAVA_HOME% . This should output the path to your Java installation folder. If it doesn't, your JAVA_HOME variable was not set correctly. Please make sure you're using the correct Java installation folder, or repeat the steps above.
Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1.
If any program that requires a Java runtime fails to find the JAVA_HOME environment variable upon startup, or if the JAVA_HOME environment variable is misconfigured, it will result in some of the following error messages to be displayed: A Java installation exists but JAVA_HOME has been set incorrectly.
You don't need to include any path in "User Variables for" section.
Just create JAVA_HOME and ANDROID_HOME variables is "System variables" section.
After that something that you may have forgotten is to include those variables in "path" variable existing in "System variables" section as below: screen capture
I eventually solved this by taking it to another device and running as administrator. So if someone ran into a similar problem try running your cmd as administrator or check its permission. After obviously trying most of what was said on this post already and in the comments
Update
One issue I found on another device recently (2 years after the original issue) is I was running a shell version of CMD not the default CMD which was not gaining access to the Java_Home property. Be sure to check that as a possible cause as well.
I had the same issue. I tried all the methods from uninstalling multiple versions, reinstalling latest version, tried inverted commas in paths etc.etc. but the problem was really one invalid path in the existing path variable!!! after removing it, this issue was solved
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With