java Android Gradle 的依赖缓存可能已损坏且 gradle build 无法正常工作

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

Android Gradle's dependency cache may be corrupt and gradle build not working

javaandroidandroid-studiogradlebuild.gradle

提问by sam_k

I am trying to import this project, even I tried to import other few projects too, I am getting below error.

我正在尝试导入此项目,即使我也尝试导入其他几个项目,但出现以下错误。

https://github.com/ashdavies/data-binding

https://github.com/ashdavies/data-binding

enter image description here

在此处输入图片说明

I have spent my 5 hours on it, even I tried many solutions on google but nothing gonna worked for me.

我已经花了 5 个小时在上面,即使我在谷歌上尝试了很多解决方案,但没有任何效果对我有用。

I tried following solutions, nothing worked.

我尝试了以下解决方案,但没有任何效果。

1) delete .gradle directory
2) Restart IDE, 
3) I tested with com.android.tools.build:gradle-experimental:0.7.0-alpha1

I am frustrated because of this Gradle and these issues.

因为这个 Gradle 和这些问题,我很沮丧。

Gradle Version : Gradle-2.13, I do not want to change this version.
Android Studio Version : Stable 2.1.1

Note : My other project is working fine and I can build it too.

注意:我的另一个项目运行良好,我也可以构建它。

回答by Farhad Faghihi

You can try different workarounds for this problem :

您可以针对此问题尝试不同的解决方法:

1- Cleanproject and Rebuildit.

1-清理项目并重建它。

2- Before importing the project, remove the contents of the Buildfolders.

2-在导入项目之前,删除Build文件夹的内容。

Then replace the contents of your gradle-wrapper.propertiesfile with the following lines, to make it use a local distribution for building the project :

然后用以下几行替换gradle-wrapper.properties文件的内容,使其使用本地发行版来构建项目:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=file\:/opt/gradle/gradle-2.13-all.zip

in which, the last line prevents android studio to download or use a corrupted gradle cache.

其中,最后一行阻止 android studio 下载或使用损坏的 gradle 缓存。

回答by Developine

Because your gradle path for project is incorrect. Go to ->Settings ->Gradle

因为您的项目 gradle 路径不正确。转到 -> 设置 -> Gradle

and select "use default gradle settings" and than sync project. and issue will be resolved.

并选择“使用默认gradle设置”而不是同步项目。问题将得到解决。

回答by Manoj Selvin

  1. Go to any browser

  2. type gradle and press enter

  1. 转到任何浏览器

  2. 输入gradle并按回车

you can specify any version you want after the

您可以在之后指定您想要的任何版本

gradle keyword

gradle 关键字

i am downloading gradle 3.3

我正在下载 gradle 3.3

  1. https://services.gradle.org/distributionsclick on this link which is in description directly if you want

  2. click on gradle 3.3 all.zip

  3. wait for the download to complete

  4. once the download is complete extract the file to the location
  1. https://services.gradle.org/distributions点击这个链接,如果你想直接在描述中

  2. 点击gradle 3.3 all.zip

  3. 等待下载完成

  4. 下载完成后,将文件解压缩到该位置

c://user/your pc name /.gradle/wrapper/dists

c://user/你的电脑名/.gradle/wrapper/dists

  1. wait till extraction it takes 5 mins to complete

  2. Now open your project in android studio

  1. 等到提取需要5分钟才能完成

  2. 现在在 android studio 中打开你的项目

9.go to file > settings >bulid ,exec,deployment > gradle

9. 转到文件 > 设置 > bulid ,exec,deployment > gradle

  1. now change use default gradle to
  1. 现在将使用默认 gradle 更改为

use local gradle distributn

使用本地 gradle 发行版

select the location where you had extracted gradle 3.3.zip

选择你解压 gradle 3.3.zip 的位置

C:\Users\your pc name.gradle\wrapper\dists\gradle-3.3

C:\Users\你的电脑名称.gradle\wrapper\dists\gradle-3.3

  1. click on OK

  2. Now build starts again and

  1. 点击确定

  2. 现在构建再次开始

you can see now the build is successful and error is resolved

您现在可以看到构建成功并且错误已解决

or

或者

watch tutorial https://www.youtube.com/watch?v=u92_73vfA8M

观看教程 https://www.youtube.com/watch?v=u92_73vfA8M

回答by Ajji

In my case, it was happening because i haven't set the JDK path in environment variable. Please check from your Android studio studio that your JDK path is correct.

就我而言,这是因为我没有在环境变量中设置 JDK 路径。请从您的 Android Studio 工作室检查您的 JDK 路径是否正确。

Go to Project Structure> SDK Location and check JDK Path. Give it the correct JDK path and also set the JAVA_HOME environment variable.

转到项目结构> SDK 位置并检查 JDK 路径。为其提供正确的 JDK 路径并设置 JAVA_HOME 环境变量。

enter image description here

在此处输入图片说明

回答by Ali Nawaz

You can try this solution as i was facing this issue showing Error2 Gradle's dependency cache may be corrupt and gradle build not working and resolved it. Already answered this question on stack. You can reffer to this answer link

您可以尝试此解决方案,因为我遇到了这个问题,显示 Error2 Gradle 的依赖项缓存可能已损坏,并且 gradle 构建无法正常工作并已解决。已经在堆栈上回答了这个问题。 你可以参考这个答案链接

It includes firstly downloading latest graddle version from official site then replacing that unzipped file with home/yourUser/.graddle/wrapper/dists containg older version file on Mac.

它包括首先从官方网站下载最新的 graddle 版本,然后在 Mac 上用包含旧版本文件的 home/yourUser/.graddle/wrapper/dists 替换解压文件。

回答by Brave Dolphin

In my case is that gradle-5.1.1-all.zip download failed, so I go to zipStoreBase+zipStorePath(configured in gradle-wrapper.properties, eg: E:\gradle-home\wrapper\dists), and delete the gradle-5.1.1-all directory, and let android studio to download that zip file again.

在我的例子中是 gradle-5.1.1-all.zip 下载失败,所以我去 zipStoreBase+zipStorePath(在 gradle-wrapper.properties 中配置,例如:E:\gradle-home\wrapper\dists),并删除gradle-5.1.1-all 目录,然后让 android studio 再次下载该 zip 文件。