Android Studio 编译失败,但是找不到错误,信息如下:

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':xxxx-ui:compileReleaseJavaWithJavac'.

    Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1 mins 40.568 secs

那是因为没有设置JAVA_HOME。如果没有设置的话需要设置JAVA_HOME.

如果你用的是Ubuntu环境的话,JAVA_HOME的设置如下:
在文件/etc/profile中,
export JAVA_HOME=/usr/local/lib/jdk1.8.0_102
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin:$PATH

还有在AndroidStudio中,查看File--Project Structure--SDK location--JDK location,看JDK location是不是正确设置了。