Unsupported major.minor version 52.0

最近使用android studio (3.4.2)编译一个工程竟然报错了

FAILURE: Build failed with an exception.

* Where:
Build file 'F:\work201907\freen\build.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':freen'.
> java.lang.UnsupportedClassVersionError: com/android/build/gradle/LibraryPlugin : Unsupported major.minor version 52.0

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

显然Unsupported major.minor version 52.0这个是说需要jdk 8,但是我默认配置的是jdk7。也就是说在控制台输入
java -version打印出来的版本是7,这个版本其实指向的是环境变量JAVA_HOME对应目录下的jdk。我们的工程下面的gradlew.bat文件有段代码这么写的

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

网上查询说是要修改File—>project structure—>SDK Location---->JDK Location,但是我修改后发现没用。我的电脑是同时安装了jdk7和jdk8的。解决方法是直接将JAVA_HOME修改为jdk8对应的目录。

你可能感兴趣的:(Android,Studio)