gradle 7.0编译报错:Android Gradle plugin requires Java 11 to run

446 阅读1分钟

背景

Android工程中gradle已升级到7.0版本。 gradle-wrapper.properties文件内容:

distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

问题

执行gradle命令时报错。

gradlew clean build

报错信息:

* What went wrong:
An exception occurred applying plugin request [id: 'com.android.application']
> 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`.

* 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.

解决方法

方案一、 修改gradle.properties,增加如下内容. 后面的路径请自行修改为自己本地的jdk或jre版本(Java 11或以上)

org.gradle.java.home=D\:/Program Files/Android/Android Studio/jre

方案二、修改环境变量JAVA_HOME的值,指向Java 11或以上

关于我

厦门大学计算机专业|华为八年高级工程师
十年软件开发经验,5年编程培训教学经验
目前从事编程教学,软件开发指导,软件类毕业设计指导。
所有编程资料及开源项目见cxyxy.blog.csdn.net/article/det…