如何修复 android 构建错误 - 无法创建 Java 虚拟机

How to fix android build error - Could not create the Java Virtual Machine

您好,我正在尝试构建 Android apk,当我 运行 shell 脚本时出现以下错误。

请问我可以做些什么来解决这个问题。

我安装了最新的JAVA

xx.xxx@OEMBP01 app-android % java -version
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)

我得到的错误是

Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/7.1.1/userguide/gradle_daemon.html
Process command line: /Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home/bin/java -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country=GB -Duser.language=en -Duser.variant -cp 

    /Users/xx.xxx/.gradle/wrapper/dists/gradle-7.1.1-all/1wqbeia0d49252rmlcr6o8lbl/gradle-7.1.1/lib/gradle-launcher-7.1.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.1.1
    Please read the following process output to find out more:
    -----------------------
    Unrecognized VM option 'MaxPermSize=512m'
    Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.
    
    
    * 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

您使用的两个 JVM 选项在最近的 Java 版本中不再可用:

这两个选项最初都被报告为警告,现在在尝试启动 VM 时会引发实际错误。

除非遇到特定问题,否则您应该能够依赖当前的默认值,因此只需从参数列表中删除 -XX:MaxPermSize=512m-XX:+UseConcMarkSweepGC(例如,在您的 gradle.properties 文件)。