Gradle 更新后项目同步失败 - 无法找到方法 'com.google.common.collect.ImmutableSet.toImmutableSet()Ljava/util/stream/Collector;'

Gradle project sync failed after update - Unable to find method 'com.google.common.collect.ImmutableSet.toImmutableSet()Ljava/util/stream/Collector;'

我最近打开了一个旧项目,将 Android Studio 更新到 3.1.3,现在无法 运行 该项目。这是我收到的消息:

Unable to find method 'com.google.common.collect.ImmutableSet.toImmutableSet()Ljava/util/stream/Collector;'.

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. 

此消息在第二次尝试时跟进此消息:

Could not initialize class com.android.build.gradle.internal.ide.ModelBuilder

Gradle Project sync failed

gradle项目同步一直失败,我已经尝试了以下所有这些解决方案,包括invalidating/restarting缓存、删除.gradle文件等

Unsuccessful solutions

我不是 Android 天才,所以如果有人能引导我朝着正确的方向前进,我将不胜感激!

我怀疑这与 Guava 中的冲突有关,具体取决于 Gradle 您使用的版本和您的依赖项使用的 Guava 版本。

Guava 21 (Guava 20 中添加了函数 toImmutableList。

我建议您尝试将项目的 gradle 版本降级到 3.3 左右,然后再试一次。