Flutter构建Android报错无法解析com.stripe:stripe-android:20.4.1
Flutter构建Android应用Stripe依赖拉取失败问题
错误表现
构建过程中触发:app:checkDebugAarMetadata任务执行失败,核心错误为拉取Stripe相关依赖包时,请求已废弃的https://google.bintray.com/exoplayer/仓库地址,服务返回502 Bad Gateway,完整错误日志如下:
What went wrong: Execution failed for task ':app:checkDebugAarMetadata'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'. > Could not resolve com.stripe:stripe-android:20.4.1. Required by: project :app > project :stripe_android > Could not resolve com.stripe:stripe-android:20.4.1. > Could not get resource 'https://google.bintray.com/exoplayer/com/stripe/stripe-android/20.4.1/stripe-android-20.4.1.pom'. > Could not GET 'https://google.bintray.com/exoplayer/com/stripe/stripe-android/20.4.1/stripe-android-20.4.1.pom'. Received status code 502 from server: Bad Gateway > Could not resolve com.stripe:financial-connections:20.4.1. Required by: project :app > project :stripe_android > Could not resolve com.stripe:financial-connections:20.4.1. > Could not get resource 'https://google.bintray.com/exoplayer/com/stripe/financial-connections/20.4.1/financial-connections-20.4.1.pom'. > Could not GET 'https://google.bintray.com/exoplayer/com/stripe/financial-connections/20.4.1/financial-connections-20.4.1.pom'. Received status code 502 from server: Bad Gateway
现有配置与已尝试操作
pubspec.yaml中Stripe依赖声明:
flutter_stripe:
- 项目级
android/build.gradle配置:
buildscript { ext.kotlin_version = '1.6.10' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:4.2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.10' } } allprojects { repositories { google() mavenCentral() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') } task clean(type: Delete) { delete rootProject.buildDir }
- 已尝试排查:确认自身业务代码和Stripe官方依赖均未引用
jcenter()仓库,多次重试构建始终报相同错误,参考常见Maven仓库配置类修复方案后问题未解决。
修复方案
这个问题和jcenter没有直接关系,根因是Bintray服务正式下线后,本地残留的旧依赖解析缓存、或者部分传递依赖携带的废弃仓库配置,会让Gradle错误地把Stripe相关依赖的拉取请求路由到早已关停的google.bintray.com地址,按以下步骤操作即可修复:
- 打开项目级
android/build.gradle文件,修改allprojects代码块下的仓库配置,添加专属解析规则,强制所有Stripe组下的依赖只从官方合法Maven源拉取,跳过所有废弃仓库的解析逻辑,修改后的allprojects配置如下:
allprojects { repositories { google() mavenCentral() // 强制Stripe相关依赖走Google官方Maven源,拦截错误的bintray路由 exclusiveContent { forRepository { google() } filter { includeGroupByRegex "com\\.stripe.*" } } } }
- 清理所有旧构建缓存和错误的依赖缓存,在项目根目录按顺序执行以下命令:
- 执行
flutter clean清理Flutter构建产物缓存 - 进入android目录,类Unix系统执行
./gradlew cleanBuildCache,Windows系统执行gradlew.bat cleanBuildCache,清理Gradle本地构建缓存 - 回到项目根目录执行
flutter pub get重新拉取Dart端依赖
- 执行
- 配置优化:不要在
pubspec.yaml中使用无版本号的flutter_stripe:声明,明确指定和当前Flutter版本匹配的稳定版号,避免拉取到存在仓库配置问题的开发版、预发布版本。
内容的提问来源于stack exchange,提问作者Rafid Kotta
相关产品推荐
相关产品推荐

