Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting JAVA_HOME at Android SDK

I have some conflicts with the JAVA_HOME configuration When I using the following code -

System.out.println(System.getenv("JAVA_HOME"));

I get - C:\jdk1.6.0_23 which is the correct place. But, When I run Ant command on an Android build.xml, I got the following error message -

C:\android-sdk-windows\tools\ant\main_rules.xml:361: Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK. It is currently set to "C:\jdk1.6.0_23\jre"

How it can be resolved?

Thanks,

Eyal

like image 534
eyal Avatar asked Jan 06 '11 08:01

eyal


People also ask

Can we set JAVA_HOME to JRE?

Set the JAVA_HOME System Variable Click the Advanced tab, and then click Environment Variables. Under System Variables, look for the JAVA_HOME system variable. The JAVA_HOME path should point to the location that you recorded when you installed the JRE.

Is JAVA_HOME set automatically?

OpenJDK's JAVA_HOME configuration tool But, it doesn't do it all by default. You must perform a custom install and select one of the following two options to have the OpenJDK installer set JAVA_HOME and PATH environment variables: add to PATH; or. set JAVA_HOME variable.

How do you fix JAVA_HOME is not set and no Java command could be found in your path?

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.


2 Answers

To permanently set your JAVA_HOME Environment Variable under Windows to the JDK directory you've mentioned do the following:

  1. Click Start, right click on Computer and select properties (you can also hold down the windows key and press the pause/break key).
  2. Click on Advanced system settings on the left.
  3. Click the Environment Variables button on the bottom.
  4. Click the New... button below the System variables window.
  5. Enter the following:

        Variable name: JAVA_HOME
        Variable value: C:\jdk1.6.0_23\ 
    
  6. Click Ok, Ok, Ok, and close the system control panel you opened in step 1
  7. Close and re-open your command prompt.

If you are using Eclipse then skip the steps above and do the following:

  1. Click on the Window menu and choose Preferences.
  2. Expand the Ant entry on the left and click on Runtime
  3. Click on Global Entries in the Classpath tab on the right.
  4. Click Add External JARs...
  5. Navigate to C:\jdk1.6.0_23\lib and select tools.jar then click open.
  6. Hit ok to Close the preferences Window.

In your situation however your best bet would probably be to simply append C:\jdk1.6.0_23\bin to your PATH env var using my first set of instructions above as a rough guideline.

like image 193
Justin Buser Avatar answered Oct 11 '22 13:10

Justin Buser


  1. Copy c:\windows\system32\java.exe to c:\windows\syswow64
  2. Set JAVA_HOME to path, use / instead of \
like image 26
Babak Avatar answered Oct 11 '22 14:10

Babak