Java Android Studio Gradle 项目同步失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23663299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 00:34:43  来源:igfitidea点击:

Android Studio Gradle project sync failed

javaandroidgradleandroid-studioandroid-gradle-plugin

提问by Sandak

I'm getting error: "Gradle project sync failed. Basic functionality (e.g. eiditing) will not work properly."

我收到错误消息:“Gradle 项目同步失败。基本功能(例如编辑)将无法正常工作。”

And Error Log:

和错误日志:

Error: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 http://gradle.org/docs/1.10/userguide/gradle_daemon.html 
Please read below 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.

I was trying to delete .gradle folder as I read here. This worked yesterday but today when I started Android Studio the error showed again and deleting .gradle folder doesn't help.

当我在这里阅读时,我试图删除 .gradle 文件夹。这昨天有效,但今天当我启动 Android Studio 时,错误再次显示,删除 .gradle 文件夹无济于事。

I realy don't know what to do.

我真的不知道该怎么办。

Does anyone have any suggestions?

有没有人有什么建议?

采纳答案by Prizoff

Just a blind guess: try to add something like this to your gradle.propertiesfile in the project:

只是盲目猜测:尝试在项目中的gradle.properties文件中添加如下内容:

org.gradle.jvmargs=-Xmx512m -XX:MaxPermSize=512m

回答by Andrew G

The only way I've been able to fix this when it happens is by doing

当它发生时我能够解决这个问题的唯一方法是做

./gradlew clean 

and

./gradlew --refresh-dependencies

and then restarting Android Studio.

然后重新启动Android Studio。

If that doesn't work I usually resort to reimporting the project.

如果那不起作用,我通常会求助于重新导入项目。

回答by Jagadish

Same issue solve in Android studio by

同样的问题在 Android Studio 中解决

File -> Settings -> Compiler (Gradle-based Android Projects)

文件 -> 设置 -> 编译器(基于 Gradle 的 Android 项目)

Change the "**VM options**" to 
-Xmx512m -XX:MaxPermSize=512m

It worked for me .

它对我有用。

回答by Prashant Maheta

I had the Same Issue, and Searched for almost 4 Days but can't able to solve the problem.

我有同样的问题,搜索了将近 4 天,但无法解决问题。

But at Last I can able to solve the problem, and for that please follow the steps.

但最后我可以解决问题,为此请按照步骤操作。

Step 1: Check Your Java Version.

Step 2: If It is 1.7 then Download the New Version i.e JDK 1.8

Step 3: Install JDK 1.8

Step 4: Change the Java Version of Android Studio to 1.8 and the problem solved...

第 1 步:检查您的 Java 版本。

第 2 步:如果是 1.7,则下载新版本,即 JDK 1.8

第 3 步:安装 JDK 1.8

第四步:将Android Studio的Java版本改为1.8,问题解决...

It Worked for me.

它对我有用。

回答by Syed Raza Mehdi

changing compile setting to this worked for me

将编译设置更改为此对我有用

enter image description here

在此处输入图片说明

回答by user3721115

Updating Java and the problem is solved!

更新Java,问题解决!

Control panel > Java > Update Now

回答by user745535

I was in that situation, finding near no solution; finally I realized that my firewall was blocking java executable from opening ports/connecting. Try adding a firewall exception for the Java executable. This solved the problem for me.

我就在那种情况下,几乎找不到解决办法;最后我意识到我的防火墙阻止了 java 可执行文件打开端口/连接。尝试为 Java 可执行文件添加防火墙例外。这为我解决了这个问题。

回答by Christine Tuazon

This one worked for me.

这个对我有用。

  1. Close the Android Studio
  2. Delete .gradlefolder from c:\users\{username}\.gradle
  3. Open the Android Studio
  4. Clean Project
  5. Rebuild Project
  6. Sync Project with gradle files. See screen shot

    Cheers!

  1. 关闭 Android Studio
  2. .gradle从中删除文件夹c:\users\{username}\.gradle
  3. 打开安卓工作室
  4. 清洁工程
  5. 重建项目
  6. 将项目与 gradle 文件同步。查看屏幕截图

    干杯!

回答by seb

Check if the gradle path in File -> Settings -> Build, Execution -> Gradleis correct. I had incorrect path to local gradle distribution there.

检查 gradle 路径File -> Settings -> Build, Execution -> Gradle是否正确。我在那里的本地 gradle 分发路径不正确。

回答by sav621

None of these worked for me, so this is how I eventually solved my problem:

这些都不适合我,所以这就是我最终解决问题的方式:

  • In the top-level buildbuild.gradle file, remove 'classpath 'com.android.tools.build:gradle:some version number'
  • sync your project and make sure your gradle location is pointing at the correct directory
  • 顶层构建build.gradle 文件中,删除 'classpath 'com.android.tools.build:gradle: some version number'
  • 同步您的项目并确保您的 gradle 位置指向正确的目录