Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - Execution failed for task ':app:compileDebugJavaWithJavac'

Tags:

New to Android Studio + Gradle.

I'm trying to run my app from the command line using:

gradlew installDebug

The app gets installed on my device only when I execute that command when Studio just got opened and do that initial syncing/building thing.

Whenever I modified my code, and try to run that command again, the build fails and shows this error:

Execution failed for task ':app:compileDebugJavaWithJavac'
> Could not find tools.jar

How do I solve this problem? Thanks in advance.

like image 794
Jeffrey Lopez Avatar asked Oct 10 '15 14:10

Jeffrey Lopez


2 Answers

Setting the JAVA_HOME variable to C:\Program Files\Java\jdkX.XX worked for me.

It was previously set to the JRE directory for some reason.

like image 100
Jeffrey Lopez Avatar answered Oct 08 '22 11:10

Jeffrey Lopez


Are you on Linux? What does echo $JAVA_HOME outputs?

I had a similar issue when running react-native run-android. After setting $JAVA_HOME (which hadn't existed) to a JDK folder, the problem was solved. In my case, I added the following line to the end of .bashrc file:

export JAVA_HOME="path/to/a/folder/with/JDK/jdk1.8.0_60"

and restarted the terminal.

like image 37
Nil Avatar answered Oct 08 '22 10:10

Nil