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

无法解析Google Play Services 15.0.2版本依赖的Gradle问题求助

解决Google Play Services 15.0.2依赖无法解析的踩坑记录

最近遇到一个头疼的依赖问题,跟大家分享下我的排查和解决过程:

一开始因为Google Play Services 15.0.0版本导致了dexing错误,于是我想着把版本升级到15.0.2试试,结果Gradle直接报错,说找不到com.google.android.gms:play-services-location:15.0.2、com.google.android.gms:play-services-basement:15.0.2、com.google.android.gms:play-services-tasks:15.0.2这三个依赖。

最奇怪的是,我自己的library模块build.gradle里根本没加过这几个依赖啊!点IDE的安装依赖按钮也提示找不到对应版本,当时真的一脸懵。

先贴一下我这个模块的build.gradle内容:

apply plugin: 'com.android.library'

def DEFAULT_COMPILE_SDK_VERSION = 25
def DEFAULT_BUILD_TOOLS_VERSION = "25.0.2"
def DEFAULT_TARGET_SDK_VERSION = 25
def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "15.0.2"

android {
    compileSdkVersion project.hasProperty('compileSdkVersion') ? project.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
    buildToolsVersion project.hasProperty('buildToolsVersion') ? project.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion project.hasProperty('buildToolsVetargetSdkVersionrsion') ? project.buildToolsVersion : DEFAULT_TARGET_SDK_VERSION
        versionCode 1
        versionName "1.0"
    }
}

repositories {
    mavenCentral()
}

dependencies {
    def googlePlayServicesVersion = project.hasProperty('googlePlayServicesVersion') ? project.googlePlayServicesVersion : DEFAULT_GOOGLE_PLAY_SERVICES_VERSION
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.facebook.react:react-native:+'
    compile "com.google.firebase:firebase-core:$googlePlayServicesVersion"
    compile "com.google.firebase:firebase-messaging:$googlePlayServicesVersion"
    compile 'me.leolin:ShortcutBadger:1.1.17@aar'
}

后来翻遍了自己的配置都没找到问题,直到去看父项目的build.gradle才发现猫腻:里面有个multidex的脚本,居然强制把所有com.google.gms的依赖版本都升级到了15.0.2!但实际上Google根本没发布这个版本的那几个play-services子库,所以才会报错找不到。

把父build.gradle里这个强制升级版本的脚本删掉之后,Gradle终于能正常解析依赖了,问题完美解决。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 07:01:53