Execution Failed For Task ':app:compiledebugjavawithjavac'. Mac

  1. Execution Failed For Task ':app:compiledebugjavawithjavac'. Macbook Pro
  2. Execution Failed For Task ':app:compiledebugjavawithjavac'. Mac Pro
  3. Execution Failed For Task ':app:compiledebugjavawithjavac'. Mac Free
  4. Execution Failed For Task ':app:compiledebugjavawithjavac'. Mac Download
Active2 years, 3 months ago

I use Android Studio and recently got the error:

Join GitHub today. GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.

Error:Execution failed for task ':app:compileDebugJavaWithJavac'. compileSdkVersion 'android-24' requires JDK 1.8 or later to compile.

Execution Failed For Task ':app:compiledebugjavawithjavac'. Macbook Pro

But I have JDK 1.8 installed already:

:Users..>java -version
java version '1.8.0_91' Java(TM) SE Runtime
Environment (build 1.8.0_91-b15) Java HotSpot(TM) 64-Bit Server VM
(build 25.91-b15, mixed mode)

How to fix it? Thanks

T D Nguyen
T D NguyenT D Nguyen
3,4012 gold badges25 silver badges50 bronze badges

8 Answers

In Android Studio open:
File >Project Structure > see if JDK location points to your JDK 1.8 directory.

Note: you can use compileSdkVersion 24

Execution Failed For Task Juan Cruz SolerJuan Cruz Soler
6,7374 gold badges30 silver badges39 bronze badges

I have a same problem for days. I found a solution which worked from me on Windows. (I also set environment variables, but don't know whether it's needed.)

Add these lines to build.gradle file:

Source: https://code.google.com/p/android/issues/detail?id=203850

Szelk BaltazárSzelk Baltazár

I installed latest jdk but it was using the older one until I did this:

Replace the old JDK path with your new jdk path.

Works like a charm now :)

Murray Foxcroft
7,0051 gold badge38 silver badges59 bronze badges
PawanPawan
602 gold badges2 silver badges12 bronze badges

Just an FYI I had this error with an Ionic project. All the commands came back pointing to the correct JDK and JAVA_HOME was set correctly.

There was an entry in my PATH to JDK 1.7bin, replacing that with the 1.8bin fixed it for me.

StevoStevo

I was also running into the same issue from the command line on my Mac, but the answer was that JAVA_HOME was getting overridden. To track down where it is getting overridden first check java from the command line:

Then check which version of Java that Gradle is using:

At this point, I still hadn't found the source of the problem. Did a little digging, and found that it was indeed overridden in my gradle.properties file even though it was showing Java 8 when I executed gradle -version:

To fix, I just deleted the java.home line from gradle.properties. Hopefully this helps if anyone else is running into the same issue from the command line.

Bradford2000Bradford2000

In Android Studio open:File > Project Structure > SDK Location > Select jdk1.8.0_101.jdk > Home

Mihir VaghelaMihir Vaghela

I was also running into the same issue from the command line on my Windows, it shows the same hint.

check JDK location in Project Structure.

In Android Studio open: File >Project Structure > see if JDK location points to your JDK 1.8 directory.

Execution Failed For Task ':app:compiledebugjavawithjavac'. Mac Pro

It should look like

I already set the correct location to JDK.

Execution Failed For Task ':app:compiledebugjavawithjavac'. Mac Free

check the java version

check the gradle version

JVM version should be 1.8.To fix it, we can add in the gradle.propertyIn gradle.properties in the .gradle directory in your HOME_DIRECTORY set org.gradle.java.home=/path_to_jdk_directory. As for me, it is like:

To verify if it is set right, we can make a gradle build task.

Francis BaconFrancis BaconExecution Failed For Task
7371 gold badge9 silver badges21 bronze badges

On Windows 10, I first checked Project Structure and it pointed to an old 1.7 jdk. I closed Android Studio then renamed the old jdks (and jre libraries for consistency) leaving the newest 1.8 library alone. When I restarted Android Studio and attempted to build the application it asked me for the Java JDK library and I gave the path to the newest 1.8 JDK library. On my system it was C:Program FilesJavajdk1.8.0_112.

scvblwxqscvblwxq

Execution Failed For Task ':app:compiledebugjavawithjavac'. Mac Download

Not the answer you're looking for? Browse other questions tagged javaandroidandroid-studio or ask your own question.