使用 0.4.3 Android Studio,错误:“Gradle 项目同步失败。基本功能(例如编辑、调试)将无法正常工作”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21347704/
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-20 04:24:05  来源:igfitidea点击:

With 0.4.3 Android Studio, error: "Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly"

androididegradleandroid-studioandroid-gradle-plugin

提问by user1406716

I have noticed that several people are having issues after upgrading to Android Studio 0.4.3 (problem with 0.4.2 also I believe). My error and debug steps so far are as follows:

我注意到有几个人在升级到 Android Studio 0.4.3 后遇到了问题(我相信 0.4.2 也有问题)。到目前为止,我的错误和调试步骤如下:

The message I see is "Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly" as shown in snapshot below.

我看到的消息是“Gradle 项目同步失败。基本功能(例如编辑、调试)将无法正常工作”,如下面的快照所示。

Error in Android Studio

Android Studio 中的错误

I found this threadand following instructions, but I still have the error. I am not able to do the following instruction in the thread: I went into Gradle settings and clicked on "use local Gradle distribution" and pointed it to*: C:/Users/robot_000/.gradle/wrapper/dists/gradle-1.10-all/6vpvhqu0efs1fqmqr2decq1v12/gradle-1.10

我找到了这个线程并遵循说明,但我仍然有错误。我无法在线程中执行以下指令: 我进入 Gradle 设置并单击“使用本地 Gradle 分发”并将其指向*:C:/Users/robot_000/.gradle/wrapper/dists/gradle-1.10 -all/6vpvhqu0efs1fqmqr2decq1v12/gradle-1.10

Do I need to have a local distribution of gradle? Where do I download it from and where do i put it? How do I now tell Android Studio to use it? (as you can tell, I don't understand how gradle works). Thanks for any help.

我需要本地分发 gradle 吗?我从哪里下载它,我把它放在哪里?我现在如何告诉 Android Studio 使用它?(如您所知,我不明白 gradle 是如何工作的)。谢谢你的帮助。

Update 1: I found the gradle files on my computer at C:\Users\home.gradle\wrapper\dists\gradle-1.10-all\6vpvhqu0efs1fqmqr2decq1v12\gradle-1.10, but how do I do do this: "went into Gradle settings and clicked on "use local Gradle distribution" and pointed it to*" (as per THIS THREAD)

更新 1:我在我的计算机上找到了 C:\Users\home.gradle\wrapper\dists\gradle-1.10-all\6vpvhqu0efs1fqmqr2decq1v12\gradle-1.10 的 gradle 文件,但是我该怎么做:“进入 Gradle 设置并单击“使用本地 Gradle 发行版”并将其指向*”(根据此线程

回答by pyus13

Go to File > Settings > Gradle you will end up with this screen for setting up your gradle :

转到文件 > 设置 > Gradle,您最终会看到这个用于设置 gradle 的屏幕:

gradle setting

渐变设置

Also make sure you have Google Repository in your Android SDK directory which will be located at :

还要确保您的 Android SDK 目录中有 Google 存储库,该目录位于:

$SDK_DIR\extras\google\m2repository\com\google\android\gms\play-services.1.36

If not do install it from SDK Manager > Extras > Google Repository first.

如果没有,请先从 SDK Manager > Extras > Google Repository 安装它。

EDIT :

编辑 :

All your build.gradle(If you are using root level build.gradleto define android gradle plugin version, check in that only) must point to 0.8version(latest as of now) of android gradle plugin

您的所有build.gradle(如果您使用根级别build.gradle来定义 android gradle 插件版本,请仅签入)必须指向0.8android gradle 插件的版本(目前最新)

 dependencies {
     classpath 'com.android.tools.build:gradle:0.8.+'
 }

UPDATED :

更新 :

Mapping is :

映射是:

 | Android Gradle Plugin |  Gradle Version |
       0.7.+                     1.9
       0.8.+                     1.10

回答by Ryan Heitner

File -> Invalidate Cache / Restart

文件 -> 使缓存无效/重新启动

Works sometimes for this

有时为此工作

回答by jojobrovado

I had the same problem and using local gradle distribution didn't work for me either. I ended up finding the solution here Gradle DSL method not found: 'runProguard'

我遇到了同样的问题,使用本地 gradle 发行版对我也不起作用。我最终在这里找到了解决方案Gradle DSL method not found: 'runProguard'

Anything above gradle version 0.14.0 has to use minifyEnabledinstead of runProguardin your projects build.gradle file. Here is how it should look :

任何高于 0.14.0 版本的 gradle 都必须在你的项目 build.gradle 文件中使用,minifyEnabled而不是使用runProguard。这是它的外观:

buildTypes {

    release {

        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}

Hope this helps. Check out the link if you are still confused

希望这可以帮助。如果您仍然感到困惑,请查看链接

回答by Kyle Falconer

I ran into this problem and found I already had the location of Gradle set and already had the Google Repository installed as mentioned by pyus13.

我遇到了这个问题,发现我已经设置了 Gradle 的位置,并且已经安装了 pyus13 提到的 Google Repository。

My solution was switching Android SDK Build-tools to a previous version fixed the problem. The latest revision was 19.1, but updating to that broke the tool chain.

我的解决方案是将 Android SDK Build-tools 切换到以前的版本解决了这个问题。最新修订版是 19.1,但更新到该版本打破了工具链。

It could just be as simple as trying another Build-tools.

它可能就像尝试另一个构建工具一样简单。

SDK Platform-tools and SDK Build-tools

SDK 平台工具和 SDK 构建工具

回答by Sindri Tór

Well i dont know what worked for them but for me worked to add a little scripts to build.gradle. DO note its important to put them at the top of the page (in build.gradle).

好吧,我不知道什么对他们有用,但对我来说,我努力向 build.gradle 添加一些脚本。请注意将它们放在页面顶部(在 build.gradle 中)很重要。

buildscript {
    repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:0.11.2'
}
}

THEN: in buildToolsVersion I had a version 19.1.0 and there for I installed build-tools (SDK manager) version 19.1 & 19. I uninstall other build-tools packetes, im not a fan of useless stuff.

然后:在 buildToolsVersion 中,我有一个版本 19.1.0,在那里我安装了构建工具(SDK 管理器)版本 19.1 和 19。我卸载了其他构建工具包,我不喜欢无用的东西。

And you should be good to go, hope it helps someone..

而且你应该很高兴,希望它可以帮助某人..

回答by DvxWifiScan

In the scope of the project, in the gradle properties file, you should add :

在项目范围内,在 gradle 属性文件中,您应该添加:

org.gradle.jvmargs=-Xmx1024m

回答by anakha

Well, I don't know what worked for them, but for me worked to add little scripts to build.gradle.

好吧,我不知道什么对他们有用,但对我来说,我努力将小脚本添加到build.gradle.

Do note that it's important to put them at the top of the page (in build.gradle).

请注意,将它们放在页面顶部(在 中build.gradle)很重要。