【问题标题】:How to fix android build error - Could not create the Java Virtual Machine如何修复 android 构建错误 - 无法创建 Java 虚拟机
【发布时间】:2022-01-23 18:03:14
【问题描述】:

您好,我正在尝试构建 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

【问题讨论】:

    标签: java android gradle jvm android-build


    【解决方案1】:

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

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

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

    【讨论】:

    • 问题可能是:OP 是否真的把它放在了某个地方,或者它到底来自哪里;-)
    • 您好,感谢您的回复,我应该从哪里删除 XX:MaxPermSize?
    • 我可以看到它作为 gradle.properties 文件的一部分 # 指定用于守护进程的 JVM 参数。 # 该设置对于调整内存设置特别有用。 org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC
    • 是的,然后从那里删除它。您可能还需要删除 +UseConcMarkSweepGC 选项(如果出现下一个错误)。那个在 Java 9 中被弃用了。
    • 我已将其删除,现在出现错误 Unrecognized VM option 'UseConcMarkSweepGC' org.gradle.jvmargs=-Xmx2048m -XX:+UseConcMarkSweepGC is UseConcMarkSweepGC required?
    猜你喜欢
    • 1970-01-01
    • 2013-10-14
    • 2017-05-30
    • 1970-01-01
    • 2018-07-17
    • 2019-08-16
    • 2013-12-07
    • 2020-05-20
    相关资源
    最近更新 更多