Skip to content
Related Articles

Related Articles

Fix “Execution Failed for task :app:compileDebugJavaWithJavac” in Android Studio

View Discussion
Improve Article
Save Article
  • Last Updated : 19 Jun, 2021
View Discussion
Improve Article
Save Article

Working on some important java project with Java code involved, and just when you hit that Build hammer icon, you get this:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

Figure 1: The Error

Well, let’s fix this error and get you up and working in no time, just follow the below methods chronologically and it will be a breeze!

Method: #1 Try updating your buildToolsVersion to “23.0.1” as follows

GeekTip: Please download the buildTools for this version with SDKManager as a hint if you haven’t already.

and then just change these in your build.gradle file

compileSdkVersion 23
buildToolsVersion "23.0.1"

then sync the Gradle file and rebuild!

Method: #2 A wrong Java Home Location or Config

Sometimes, it might be the slightest error in your $JAVA_HOME configuration which is tabbing this error, just fix it like this:

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home"

GeekTip: Make Change this in the .bash profile

Method: #3 Fixing those extra .jar dependencies

Double-check the build of your app. gradle. It adds an extra.jar file as a dependency that didn’t exist in your project. As a result, remove that and you’re back on track!

Method: #4 For the newer versions of Android Studio

If you happen to be running the latest version of Android Studio or the Canary Flavor of the IDE then maybe the issue is there with the certain sdkVersions of your project. Change it this way:

Navigate to File > Project Structure


change the compileSdkVersion to any value (like 24) which works with your project like

compileSdkVersion 24

Method: #5 If you’re rocking the RETROLAMBDA Build Script

If you’re using the retrolambda build script then you may change its configuration in the build.gradle and your error might be resolved

retrolambda {
    jdk System.getenv("JAVA_HOME")
    oldJdk System.getenv("JAVA7_HOME")
    javaVersion JavaVersion.VERSION_1_8

GeekTip: You can also establish a new environment variable named JAVA8 HOME that points to the correct JDK location.

That’s it if you followed the methods given in this article you would’ve resolved this issue and would be back on the track with that project building perfectly as intended!

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!