在执行gradlew命令的时候报错,日志如下:
* 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 17 to run. You are currently using Java 11. Your current JDK is located in /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home 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. * Get more help at https://help.gradle.org BUILD FAILED in 10s
什么是 org.gradle.java.home 属性?
在Gradle构建工具中, org.gradle.java.home 属性用于指定Gradle在构建过程中使用的Java JDK的安装路径。它是一个全局属性,可以在项目级别或全局级别进行设置。当Gradle构建项目时,它将使用指定的JavaJDK版本来编译和运行项目代码。
默认情况下,Gradle将使用系统默认的JavaJDK。但是,在某些情况下,您可能希望使用不同的JavaJDK版本,比如您的项目需要特定版本的Java或需要与其他项目兼容。
在 gradle.properties 文件中,添加以下代码
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/
当Gradle下次构建项目时,它将使用指定的Java JDK版本。