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 dependenciescommand in your project's root directory. This generates a full dependency tree—look for multiple versions of Guava (group IDcom.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(orbuild.gradle.ktsif you're using Kotlin DSL):
Pro tip: You can check the latest Guava Android version to pick the most up-to-date one that fits your project.configurations.all { resolutionStrategy.force 'com.google.guava:guava:32.1.3-android' // Use the latest Android-compatible stable version }
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 clickInvalidate and Restartto clear Studio's internal caches. - Run
./gradlew clean build --refresh-dependenciesin your terminal. This deletes old build outputs and pulls fresh copies of all dependencies.
- Open Android Studio, go to
3. Remove Redundant or Misplaced Dependencies
- Double-check your project-level and app-level
build.gradlefiles 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:dependenciesfor 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
相关产品推荐
相关产品推荐

