用 Android Studio Gradle 构建项目,gradle 在做同步时报错:

Error:Unable to start the daemon process: could not reserve enough space for
object heap.            
Please assign more memory to Gradle in the project's gradle.properties file.
For example, the following line, in the gradle.properties file,
sets the  maximum Java heap size to 1,024 MB:
org.gradle.jvmargs=-Xmx1024m

问题解决,方法一

在项目的 gradle.properties 文件中添加一行,设置 jvm 的 MaxHeapSize 值

org.gradle.jvmargs=-XX\:MaxHeapSize\=1256m -Xmx1256m

方法二

  1. 打开Android studio,然后关闭所有的项目(File-> Close Project),进入了欢迎的窗口
  2. Configure > Settings->Build, Execution, Deployment > Compiler
  3. 修改Build process heap size (Mbytes) 值为 1024
  4. 修改 Additional build process to VM Options 值为 -Xmx1512m.

方法一有时不会奏效,就可以使用方法二…