Android集成Firebase与Maps API遇版本冲突,请求排查原因
Hey there! Let's break down why you're hitting this Gradle conflict and how to fix it.
Why This Conflict Happens
The core issue is a version mismatch between your google-services plugin and the com.google.android.gms libraries (which includes the Google Maps API). Google requires these two to be compatible: the google-services plugin handles dependency resolution for Firebase and Google Play Services, and if its version doesn't align with the library versions you're using, Gradle throws this conflict error.
Step-by-Step Fixes
You have two valid paths to resolve this, as the error message suggests:
Option 1: Update the google-services Plugin to the Latest Version
- Open your project-level
build.gradlefile (this is the one in your root project folder, not the module-levelappfolder). - Look for the
dependenciesblock underbuildscript, find the line starting withclasspath 'com.google.gms:google-services:'. - Replace the version number with the latest stable version. You can get this directly from Android Studio's Gradle sync prompt, or check the SDK Manager's Google Play Services section.
Example updated line:classpath 'com.google.gms:google-services:4.3.15' - Sync your Gradle project to apply the change.
Option 2: Upgrade com.google.android.gms to Version 12.0.1 (or Higher Compatible Version)
- Open your module-level
app/build.gradlefile. - Find all dependencies related to
com.google.android.gms(like the Google Maps dependency:implementation 'com.google.android.gms:play-services-maps:x.x.x'). - Set their version to
12.0.1(or a higher version that's compatible with your currentgoogle-servicesplugin). - Critical Note: Make sure all Firebase dependencies (e.g.,
com.google.firebase:firebase-auth:x.x.x) also use the same version as yourcom.google.android.gmslibraries—this avoids sub-conflicts.
Pro Tip to Avoid Future Conflicts
Use a shared variable to manage all Google library versions in your module-level build.gradle. This way you can update all versions in one place:
ext { googleServicesVersion = "12.0.1" // Or your chosen compatible version } dependencies { implementation "com.google.android.gms:play-services-maps:$googleServicesVersion" implementation "com.google.firebase:firebase-analytics:$googleServicesVersion" // Add other Google/Firebase dependencies here using the variable }
内容的提问来源于stack exchange,提问作者James Boyle

