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

引入google play-services添加地图时遇com.android.support版本一致错误

解决Android Support库版本不一致问题

你碰到的这个all com.android.support libraries must use the exact same version specification错误,根源其实在你依赖里的com.google.android.gms:play-services:+这一行——用通配符+会让Gradle自动拉取最新版本的Play Services库,而这个新版本依赖的Android Support库版本,和你项目里固定的27.1.1不匹配,就触发了版本冲突。

接下来按这两步改就能解决:

1. 替换Play Services依赖,不用通配符,指定兼容的具体版本

首先别再用整个play-services包(它包含所有Google服务,体积超大),只引入你需要的地图模块就行。另外,必须指定和你的Support库版本兼容的具体版本——针对27.1.1的Support库,对应的Play Services版本是15.x系列(16.x及以后的版本已经切换到AndroidX了,和你当前的Support库不兼容)。比如改成:

implementation 'com.google.android.gms:play-services-maps:15.0.1'

2. 强制所有依赖统一使用你的Support库版本

在你的build.gradle(Module级别)里添加一段配置,强制所有第三方依赖引入的Support库,都替换成你指定的27.1.1版本,彻底杜绝版本不一致的问题:

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '27.1.1'
            }
        }
    }
}

修改后的完整依赖示例

把你的dependencies块改成这样:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    // 替换成具体的地图模块和兼容版本
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'de.hdodenhof:circleimageview:2.1.0'
}

改完之后同步一下Gradle,这个版本冲突的问题应该就解决啦。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 09:06:29