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

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.


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.


I deleted .gradle file from project root directory and rebuilt the app and then everything was working fine.