问题描述
把Gradle插件版本更新到7.0.2 之后编译失败,出现如下错误:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
解决思路
解决思路来自stackoverflow
用终端进入项目所在位置,找到gradlew 并执行如下命令
$ ./gradlew --version
会输出类似这样的信息,我们需要关注的是JVM 版本
Welcome to Gradle 7.0.2!
Here are the highlights of this release:
- File system watching enabled by default
- Support for running with and building Java 16 projects
- Native support for Apple Silicon processors
- Dependency catalog feature preview
For more details see https://docs.gradle.org/7.0.2/release-notes.html
------------------------------------------------------------
Gradle 7.0.2
------------------------------------------------------------
Build time: 2021-05-14 12:02:31 UTC
Revision: 1ef1b260d39daacbf9357f9d8594a8a743e2152e
Kotlin: 1.4.31
Groovy: 3.0.7
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 17 (Oracle Corporation 17+35-LTS-2724)
OS: Mac OS X 11.6 x86_64
如果JVM指向1.8版本,我们应该把它设置为该Gradle版本需要的版本。 Preferences > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK
|