【问题标题】:Unable to find method (can't compile project) after gradle updategradle更新后找不到方法(无法编译项目)
【发布时间】:2017-12-05 09:20:11
【问题描述】:

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

我当前的 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'
        ....
    }
    ....
}

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

错误:(1, 0) 找不到方法 'com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V'。 此意外错误的可能原因包括:

  • Gradle 的 依赖项缓存可能已损坏(这有时会在网络连接后发生 连接超时。)重新下载依赖项 和同步项目(需要网络)
  • Gradle 的状态 构建过程(守护进程)可能已损坏。停止所有 Gradle 守护进程可能 解决这个问题。停止 Gradle 构建 进程(需要重新启动)
  • 您的项目可能正在使用 与其他插件不兼容的第三方插件 请求的项目或 Gradle 版本 项目。
在 Gradle 进程损坏的情况下,您可以 还可以尝试关闭 IDE,然后终止所有 Java 进程。
  • 我尝试清理项目

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

  • 我在我的主目录和我的 项目,但我得到了同样的错误。

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

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

【问题讨论】:

  • 你已经尝试了一切,所以可能是第三个原因是问题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.
  • 我怎样才能知道它是哪个插件?

标签: java android android-studio gradle android-gradle-plugin


【解决方案1】:

问题是我的 buildscript 依赖项中有 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 行:

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,问题就解决了。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2016-08-05
  • 1970-01-01
  • 2020-04-13
  • 1970-01-01
  • 2020-12-10
  • 2019-07-11
  • 2022-11-19
  • 2020-09-16
相关资源
最近更新 更多