Android Studio:无法加载类"com.google.common.base.Preconditions",Gradle同步失败 [英] Android Studio: Unable to load class 'com.google.common.base.Preconditions', Gradle Sync Failed
问题描述
当我尝试在Android Studio 3.1.2上打开项目时,出现此Gradle Project Sync失败错误,并显示以下消息
When i try opening my projects on Android Studio 3.1.2, I get this Gradle Project Sync failed error with the message below
无法加载类"com.google.common.base.Preconditions".可能的 导致此意外错误的原因包括:
- Gradle的依赖项 缓存可能已损坏(网络连接后有时会发生这种情况 超时.)重新下载依赖项并同步项目(要求 网络)
- Gradle构建过程(守护程序)的状态可能是 腐败.停止所有Gradle守护程序可以解决此问题.停止 Gradle构建过程(需要重新启动)
- 您的项目可能是 使用与其他插件不兼容的第三方插件 项目中要求的插件或Gradle要求的版本 项目.
Unable to load class 'com.google.common.base.Preconditions'. Possible causes for this unexpected error include:
- 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.
gradle-wrapper.properties文件
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
build.gradle文件
buildscript {
ext.kotlin_version = '1.2.41'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
apply plugin: 'kotlin'
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
推荐答案
问题已解决.
我删除了主用户目录中的.gradle文件夹,这使Android Studio重新下载了gradle当前版本的所有文件.第一次下载和同步花了很长时间,但是已经解决了这个问题.
I deleted the .gradle folder in my home user directory which made Android Studio re-download all the files for the current version of gradle. It took quite a while to download and sync the first time but it has solved the problem.
非常感谢@Luis Henriques的帮助
Thank you very much for your assistance @Luis Henriques
这篇关于Android Studio:无法加载类"com.google.common.base.Preconditions",Gradle同步失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!