I can't seem to get my Android applications to compile due to a really annoying exception from Android Studio:
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?
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.
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.
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.
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.
Go To Settings->Project Structure->JDK path and change it to the system JDK instead of Studio JDK, you will be up and running.
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