启动Android项目时遇异常:找不到com.google.gms:google-services:3.1.1
解决「Could not find com.google.gms:google-services:3.1.1」异常
嘿,这个问题我熟得很!你碰到的这个错误,核心原因就是项目根目录的build.gradle里少了google-services插件的依赖配置,而且得确认仓库设置能正确拉取到这个官方依赖包。
具体修复步骤
- 打开项目根目录的
build.gradle(就是标注「Project: android」的那个文件) - 在
buildscript块的dependencies里,添加google-services的classpath依赖 - 确保
buildscript下的repositories里有google()(这是拉取谷歌官方依赖的关键仓库,比jcenter优先级更高)
修改后的完整配置代码如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() // 优先用谷歌官方仓库,确保能拿到正确的依赖 jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.1.1' // 新增这一行,引入google-services插件 classpath 'com.google.gms:google-services:3.1.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
额外提醒
- 要是你的Gradle版本比较老(低于3.0),
google()仓库可能不被支持,这时候可以把它换成maven { url 'https://maven.google.com' } - 别忘了在你的app模块的
build.gradle(标注「Module: app」的那个)末尾加上apply plugin: 'com.google.gms.google-services',这样才能让这个插件生效哦!
内容的提问来源于stack exchange,提问作者New GenerationFashion
相关产品推荐
相关产品推荐

