Android studio Gradle 无法启动守护进程

时间:2021-07-25 14:52:41

标签: android-studio gradle android-gradle-plugin build.gradle gradle-plugin

我想尝试使用 android studio,但是当我创建一个项目时出现此错误:

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/6.7.1/userguide/gradle_daemon.html
Process command line: C:\Program Files\Android\Android Studio\jre\bin\java.exe --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.prefs/java.util.prefs=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\laszl\.gradle\wrapper\dists\gradle-6.7.1-bin\bwlcbys1h7rz3272sye1xwiv6\gradle-6.7.1\lib\gradle-launcher-6.7.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.7.1
Please read the following process output to find out more:
-----------------------
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000080000000, 268435456, 0) failed; error='The paging file is too small for this operation to complete' (DOS error/errno=1455)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 268435456 bytes for Failed to commit area from 0x0000000080000000 to 0x0000000090000000 of length 268435456.
# An error report file with more information is saved as:
# C:\Users\laszl\.gradle\daemon\6.7.1\hs_err_pid30736.log

-----------------------
Check the JVM arguments defined for the gradle process in:
 - gradle.properties in project root directory

据我所知,我需要更多内存,但我有 16gb 内存,而 android studio 已经在使用 12gb。

1 个答案:

答案 0 :(得分:0)

JVM 使用一种称为 heap 的东西来决定它在执行必要任务时将占用多少内存。您可以将其视为在运行时保存用户定义数据类型的地方。它类似于 RAM,但不完全

两种解决方案

  1. 您可以使用基于 this gui 的方式来管理大型项目的堆空间

  2. 如果您更喜欢非 gui 方式,这总是更可靠,这是我从我的一个项目中附加的示例 gradle.properties 文件 请注意,1024m 指定了分配给 JVM 用于堆存储的 RAM 量(1024MB)。你可以在你的情况下加倍,即2048M甚至三倍

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
org.gradle.daemon=true
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx7g -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true