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

Android集成Firebase与Maps API遇版本冲突,请求排查原因

Fixing Gradle Version Conflict with Firebase & Google 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

  1. Open your project-level build.gradle file (this is the one in your root project folder, not the module-level app folder).
  2. Look for the dependencies block under buildscript, find the line starting with classpath 'com.google.gms:google-services:'.
  3. 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'
    
  4. Sync your Gradle project to apply the change.

Option 2: Upgrade com.google.android.gms to Version 12.0.1 (or Higher Compatible Version)

  1. Open your module-level app/build.gradle file.
  2. 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').
  3. Set their version to 12.0.1 (or a higher version that's compatible with your current google-services plugin).
  4. Critical Note: Make sure all Firebase dependencies (e.g., com.google.firebase:firebase-auth:x.x.x) also use the same version as your com.google.android.gms libraries—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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 04:11:45