23

I am getting following error while trying to run my app from android studio

Execution failed for task ':app: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.

After searching on internet, I found some solution like this

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_45/ 

so i gave this command in terminal from android studio dirctory but its not workout it show the same error again.

Piyush Agarwal
  • 25,608
  • 8
  • 98
  • 111
Hari Haran
  • 1,543
  • 4
  • 13
  • 25
  • http://stackoverflow.com/questions/15985363/cannot-get-the-system-java-compiler-please-use-a-jdk-not-a-jre see this – rajshree Feb 21 '14 at 04:40
  • If you are on Wiondows try to run `echo %JAVA_HOME%` and `echo %PATH%` in command prompt and include the outputs in question. – Piyush Agarwal Feb 21 '14 at 07:25

7 Answers7

69

Updating my Gradle build version did the trick for me.

Old:

classpath 'com.android.tools.build:gradle:1.0.0'

New:

classpath 'com.android.tools.build:gradle:2.2.3'

Edit: Since this answer is still being used frequently, note that Gradle 2.2.3 can probably be substituted with any newer version of Gradle. This version just happened to be the version I was using when I originally answered the question.

eatcrayons
  • 1,542
  • 15
  • 17
51

In your android-studio find it in File->Other Settings->Default Project Structure->SDKs. Then i changed JDK home path.

Hari Haran
  • 1,543
  • 4
  • 13
  • 25
5

To fix this error in Andriod Studio 2.3.1 I had to go to File > Project Structure or Ctrl+Alt+Shift+S then go to SDK Location which was already open for me and then uncheck "Use embedded JDK" and point to where my installed version was.

Xavier Guihot
  • 54,987
  • 21
  • 291
  • 190
Brockenstein
  • 86
  • 1
  • 3
2

To fix this error in Andriod Studio 2.3.1 I had to go to File > Project Structure or Ctrl+Alt+Shift+S then go to SDK Location which was already open for me and then uncheck "Use embedded JDK" and point to where my installed version was.

*

The mentioned post really solved my problem after long searching.

*

1

In the android studio

Window -> preferences -> Java -> Installed JREs and select your JDK home path

or else please follow the link to set JAVA_HOME in linux machines

Sasikumar Murugesan
  • 4,412
  • 10
  • 51
  • 74
1

In your android-studio find it in File->Other Settings->Default Project Structure->SDKs.
Then Check with JDK LOCATION select Installed JDK Location and APPLY IT.

Amit Walke
  • 293
  • 3
  • 6
0

I have this problem a lot when I try to open older projects for the first time. It seems that I just need to update the classpath under build.gradle:

In my case the old version was:
classpath 'com.android.tools.build:gradle:1.3.0'
and I updated to:
classpath 'com.android.tools.build:gradle:2.3.2'

Sync the gradle and it should compile.

Toby
  • 141
  • 3
  • 12