Gradle报错:依赖库版本不一致,添加Glide后触发该问题求助
Hey there! That error is super common when working with Google Services plugins and third-party libraries like Glide—let's break down how to fix it.
What's Causing This?
The error usually pops up because the com.google.gms.google-services plugin enforces that all Google Play Services and Firebase dependencies in your project use the exact same version. When you added Glide, it might have indirectly pulled in a version of a Google library that clashes with the ones already in your project.
Step-by-Step Solutions
1. Define Unified Version Variables
First, centralize your dependency versions in your project's root build.gradle file. This makes it easy to keep everything in sync:
buildscript { ext { // Use the latest stable versions here (check Google's docs for updates) google_services_version = "4.4.1" glide_version = "4.16.0" } repositories { google() mavenCentral() } dependencies { classpath "com.google.gms:google-services:$google_services_version" } }
Then, update your Module:app build.gradle to use these variables for all relevant dependencies:
dependencies { // Glide dependencies with explicit version implementation "com.github.bumptech.glide:glide:$glide_version" annotationProcessor "com.github.bumptech.glide:compiler:$glide_version" // All Google/Firebase dependencies use the unified version implementation "com.google.firebase:firebase-auth:$google_services_version" implementation "com.google.android.gms:play-services-location:$google_services_version" // Add any other Google/Firebase dependencies you're using here } // Keep this plugin at the bottom of your app-level build.gradle apply plugin: 'com.google.gms.google-services'
2. Force Resolve Dependency Conflicts
If you still see the error, run this command in your terminal to generate a dependency tree and spot conflicting versions:
# macOS/Linux ./gradlew app:dependencies # Windows gradlew.bat app:dependencies
Look for any com.google.android.gms or com.google.firebase entries with mismatched versions. Then add a resolution strategy to your app-level build.gradle to force those dependencies to use your unified version:
configurations.all { resolutionStrategy.force "com.google.android.gms:play-services-base:$google_services_version" resolutionStrategy.force "com.google.firebase:firebase-core:$google_services_version" // Add other conflicting dependencies you found here }
3. Verify Plugin and Dependency Compatibility
Make sure the version of the com.google.gms.google-services plugin matches the Google Play Services dependencies you're using. Generally, using the latest stable version of both will avoid compatibility issues.
Quick Note About Glide
If you're using any Glide extensions that integrate with Firebase (like glide-integration-firebase), double-check that those also use versions compatible with your unified Google Services setup. For basic Glide usage though, this shouldn't be an issue.
Give these steps a shot—they should resolve the version mismatch error!
内容的提问来源于stack exchange,提问作者Dean

