Gradle的依赖缓存可能已经损坏(这有时会在网络连接超时后发生)。

113

我收到了这种错误,如何修复它。

Error:Unable to load class 'org.gradle.tooling.internal.protocol.test.InternalTestExecutionConnection'.
Possible causes for this unexpected error Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

请检查我的答案。在我的情况下,这是JDK路径问题。 https://dev59.com/75jga4cB1Zd3GeqPI1v0#44583007 - Ajji
当您的Gradle下载中途断开互联网连接时,会出现问题。因此,请转到C:\ Users \ your username \ .gradle \ wrapper \ dists \ gradle-6.5-bin并删除zip文件。重新打开项目,Gradle将开始再次下载100MB文件。 - Abdul Wahid
41个回答

0

这里下载适用于您的操作系统的gradle,然后提取文件并将内部文件夹粘贴到installLocation/gradle中。

然后在Android Studio中转到 文件 > 设置 > 构建、执行、部署 > gradle,并选择本地gradle选项,提供新下载的gradle文件的文件路径,然后点击确定即可运行 :)


0
  1. 删除 C:\Users\Administrator.gradle\caches\xxx (xxx 为 gradle 版本)
  2. 重新构建

0

我在克隆AnySoftKeyboard并在Android Studio中打开后遇到了类似的问题。对我有用的是删除AynSoftKeyboard/gradle文件夹,然后通过菜单项Build > Clean Project清理项目。

因此,请尝试删除YourProject/gradle文件夹并清理项目以触发Gradle同步。

希望这对您有所帮助。


0

有时问题出在项目文件中的gradle wrapper文件上。打开当前项目的gradle文件,删除gradle wrapper.zip文件,然后同步项目,这样就可以解决。


0

只需删除 gradle 文件夹,然后让 Android Studio 点击 立即同步 即可再次下载它!


0
如果这是在升级了Android Studio之后发生的,可能是由于构建工具过期所致,请更新Android SDK构建工具

0

我曾经遇到过这个问题,我只是在 c://user/你的电脑名/ 中删除了所有与 Android 相关的内容,然后问题就解决了。


我曾经遇到过同样的问题,尝试删除了所有内容,但仍然得到了相同的错误。 - Savita Sharma

0

我遇到了同样的问题, 我打开了文件: my-project/gradle/wrapper/gradle-wrapper.properties, 将distributionUrl替换为

distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

我打开了文件:my-project/build.gradle,在buildscript -> dependencies下,将classpath替换为
classpath 'com.android.tools.build:gradle:4.0.0'
同步项目后,一切正常。

0

现在,2021年3月,gradle 3.4.1-all对我来说无法工作,并出现了损坏错误。因此,在build.gradle(project:)中,我使用以下元素:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }

        maven {
            url "https://s3.amazonaws.com/repo.commonsware.com"
        }
        maven { url "https://jitpack.io" }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.2'

        classpath 'com.google.gms:google-services:4.3.5' // If you use play service 

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
        maven {
            url "https://s3.amazonaws.com/repo.commonsware.com"
        }
        maven {
            url "https://maven.google.com"
        }
        maven { url "https://jitpack.io" }
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

0
在我的情况下,问题出在这一行代码:

Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

我的项目使用了一个第三方插件,该插件与最新的gradle插件版本不兼容。因此,更新插件版本可能有助于解决问题。


它是哪个插件? - Janusz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接