Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

AndroidStudio 報錯 Gradle sync failed 的解決辦法

編輯:關於 Android 程式設計

初次使用 AndroidStudio 時,很多人會遇到 Gradle sync failed 的錯誤。本文記錄了一次典型的排查與解決過程,希望能幫到有相同困擾的朋友。

一、異常信息

報錯內容如下:

 Gradle sync failed: 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 guide chapter on the daemon at https://docs.gradle.org/2.10/userguide/gradle_daemon.html Please read the following process output to find out more: ----------------------- Error occurred during initialization of VM Could not reserve enough space for object heap Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. Consult IDE log for more details (Help | Show Log) 

二、排查過程

剛開始接觸 AndroidStudio 時,我在網上查到很多說法,一直以為是 gradle.properties 文件中的這行配置出了問題:

 org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

也就是懷疑 -Xmx1024m 的值設置得太小。折騰了很久之後才發現,真正的原因其實是自己的電腦內存太小——只有 2G,而 Windows 系統本身差不多就要佔掉 1G 左右。

三、解決辦法

因此,只要把 -Xmx1024m 改為更小的 -Xmx512m,就能解決這個問題:

 org.gradle.jvmargs=-Xmx512m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

以上就是對 AndroidStudio 這一錯誤的整理,後續會繼續補充相關資料。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved