gpt4 book ai didi

java - gradle更新后无法找到方法(无法编译项目)

转载 作者:搜寻专家 更新时间:2023-11-01 07:45:42 24 4
gpt4 key购买 nike

我尝试在我的项目中将 gradle 版本更新为 4.1-milestone-1 之后 these instructions

我当前的 gradle-wrapper.properties 文件:

#Sat Jun 17 21:17:43 IDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=\
https\://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip

我当前项目build.gradle文件buildscript

buildscript {
ext.kotlin_version = '1.1.3'
apply from: 'dependencies.gradle'
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha5'
....
}
....
}

尝试编译项目时出现此错误:

Error:(1, 0) Unable to find method 'com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V'. 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.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

  • 我尝试清理项目

  • 我尝试点击重新下载依赖项和同步项目,但我得到了同样的错误。

  • 我删除了主目录和我的目录中以前的 .gradle 文件项目,但我得到了同样的错误。

  • 我尝试终止 java 进程和 android studio 但我得到了同样的错误。

  • 我尝试杀死所有 gradle 的守护进程,但我得到了同样的错误

最佳答案

问题是我的构建脚本依赖项中有 firebase,所以它看起来像这样:

buildscript {
ext.kotlin_version = '1.1.3-2'
apply from: 'dependencies.gradle'
repositories {
...
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha6'
classpath ('com.google.firebase:firebase-plugins:1.1.0') //the firebase line
....
}
}

我终于通过用这个替换 firebase 类路径行解决了这个问题:

classpath ('com.google.firebase:firebase-plugins:1.1.0') {
exclude group: 'com.google.guava', module: 'guava-jdk5'
}

所以现在我的 gradle 构建脚本看起来像这样

 buildscript {
ext.kotlin_version = '1.1.3-2'
apply from: 'dependencies.gradle'
repositories {
...
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha6'
classpath ('com.google.firebase:firebase-plugins:1.1.0') {
exclude group: 'com.google.guava', module: 'guava-jdk5'
}
....
}
}

在那之后,我所要做的就是清理项目,杀死 gradle 守护进程

./gradlew --stop

然后重启studio,问题解决。

关于java - gradle更新后无法找到方法(无法编译项目),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44862981/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com