You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gradle同步失败:ImmutableMultimap无法访问其父类AbstractMultimap

Hey there, let's figure out this annoying Gradle build error you're facing! That message about com.google.common.collect.ImmutableMultimap being unable to access its parent class com.google.common.collect.AbstractMultimap almost always ties back to Guava dependency conflicts or wonky build caches. Here are some practical fixes to try out:

1. Hunt Down Guava Dependency Conflicts
  • Start by running the ./gradlew dependencies command in your project's root directory. This generates a full dependency tree—look for multiple versions of Guava (group ID com.google.guava) being pulled in by different libraries or modules.
  • If you spot conflicting versions, force a consistent, stable Guava version across your entire project. Add this snippet to your app-level build.gradle (or build.gradle.kts if you're using Kotlin DSL):
    configurations.all {
        resolutionStrategy.force 'com.google.guava:guava:32.1.3-android' // Use the latest Android-compatible stable version
    }
    
    Pro tip: You can check the latest Guava Android version to pick the most up-to-date one that fits your project.
2. Wipe Caches and Rebuild from Scratch
  • Corrupted build files or caches often cause weird access issues like this. Try these steps:
    • Open Android Studio, go to File > Invalidate Caches..., check all the boxes, and click Invalidate and Restart to clear Studio's internal caches.
    • Run ./gradlew clean build --refresh-dependencies in your terminal. This deletes old build outputs and pulls fresh copies of all dependencies.
3. Remove Redundant or Misplaced Dependencies
  • Double-check your project-level and app-level build.gradle files to make sure you haven't added Guava dependencies multiple times by accident. Delete any duplicate entries.
  • If you're using libraries that bundle their own Guava (like certain Firebase or Google Play Services libraries), make sure their bundled version is compatible with the one you're forcing (if you used step 1).
4. Align Java Version with Guava Requirements
  • Newer Guava versions (30 and above) require at least Java 8. Verify your project's Java settings in the app-level build.gradle:
    android {
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        // For Kotlin projects, add this too
        kotlinOptions {
            jvmTarget = '1.8'
        }
    }
    
5. Check Multi-Module Dependency Leaks
  • If your project has multiple modules, run ./gradlew :module-name:dependencies for each module to check if one is using an incompatible Guava version that's causing conflicts in the main app. Adjust the version in that module or force the consistent version across all modules.

After working through these steps, rebuild your project and see if the error disappears. If it's still sticking around, feel free to share snippets of your dependency tree or relevant parts of your build.gradle files for further troubleshooting!

内容的提问来源于stack exchange,提问作者Rahul Srivastava

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:15:34