Flutter Android构建失败:获取play-services-location依赖返回502 Bad Gateway
问题解决方案
根本原因
本次构建失败是因为请求已关停的Bintray服务返回502错误:JFrog早在2021年就正式停止了Bintray、JCenter的服务,谷歌也已将所有安卓官方依赖迁移到
google()、mavenCentral()仓库,旧配置中指向Bintray的依赖拉取地址已全部失效。
修复步骤
- 第一步:移除废弃仓库配置
打开项目级build.gradle文件,删除buildscript和allprojects代码块中的jcenter()配置,确保仅保留google()和mavenCentral(),修改后配置如下:
buildscript { ext.kotlin_version = '1.4.21' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:4.0.1' classpath 'com.google.gms:google-services:4.3.4' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1' } } allprojects { repositories { google() mavenCentral() } }
- 第二步:强制指定play-services-location版本
在allprojects代码块中添加依赖版本强制规则,避免location插件请求动态版本16.+时调用废弃地址:
allprojects { repositories { google() mavenCentral() } // 新增以下配置 configurations.all { resolutionStrategy { force 'com.google.android.gms:play-services-location:16.0.0' // 如果后续需要更高版本也可以替换为20.0.0等稳定版 } } }
- 第三步:清理缓存重新构建
依次执行以下操作清理旧缓存后重试构建:
- 执行
flutter clean清理项目构建缓存 - 删除项目
android目录下的.gradle文件夹,清除gradle本地缓存 - 重新执行
flutter run或打包命令
如果以上步骤完成后仍存在问题,可以将location插件升级到最新兼容版本,替换pubspec.yaml中的location: ^4.3.0为更高的稳定版即可。
内容的提问来源于stack exchange,提问作者Sanjay Kumar
相关产品推荐
相关产品推荐

