Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio can't find JAVA_HOME

I can't seem to get my Android applications to compile due to a really annoying exception from Android Studio:

]()![enter image description here

Execution failed for task ':myapp-services:compileDebugJava'.
    Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

I'm on Ubuntu 12.04, and I'm running Oracle's Java 7 JRE/JDK.

In ~/.bashrc:

export JAVA_HOME="/usr/lib/jvm/java-7-oracle/"

In android-studio/bin/studio.sh:

export JAVA_HOME="/usr/lib/jvm/java-7-oracle/"

Output of javac -version:

javac 1.7.0_51

Output of java -version:

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

Output of printenv JAVA_HOME:

/usr/lib/jvm/java-7-oracle

Output of which javac:

/usr/bin/javac

I have also logged out and logged back in again to my session.

I'm really not sure what I'm missing here. Why can't Android Studio compile my application?

like image 927
Naftuli Kay Avatar asked Feb 24 '14 23:02

Naftuli Kay


People also ask

Why JAVA_HOME is not working?

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.

Where can I find JAVA_HOME?

Finding the Java Home Directory The JAVA_HOME environment variable needs to point to the installation directory on your system that contains the bin/ directory where the java executable physically resides, and the lib/ directory which contains the core java libraries and properties files.

Where is Java path in Android Studio?

Navigate to File > Project Structure > SDK Location. Upon navigating there you will find that a tab named “JDK Location”, select that and then you can set the JDK path for the current project on which you're working.

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

Select "Advanced system settings" then click the "Environment Variables" button. Click System Variables, New write Variable Name to "JAVA_HOME" and write Variable Value to Java installation folder address then click OK finish it. JAVA_HOME should point to jdk directory and not to jre directory.


1 Answers

Go To Settings->Project Structure->JDK path and change it to the system JDK instead of Studio JDK, you will be up and running.

like image 100
Kiran Maniya Avatar answered Oct 23 '22 17:10

Kiran Maniya