Flutter应用构建失败:无法解析Facebook Android SDK依赖求助
解决Flutter构建时Facebook SDK依赖解析失败问题
错误信息
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:checkDebugAarMetadata'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'. > Could not resolve com.facebook.android:facebook-android-sdk:latest.release. Required by: project :app > Failed to list versions for com.facebook.android:facebook-android-sdk. > Unable to load Maven meta-data from https://jcenter.bintray.com/com/facebook/android/facebook-android-sdk/maven-metadata.xml. > Could not HEAD 'https://jcenter.bintray.com/com/facebook/android/facebook-android-sdk/maven-metadata.xml'. > Read timed out * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 2m 8s Exception: Gradle task assembleDebug failed with exit code 1 Exited (sigterm)
已尝试操作
- 在build.gradle中添加
mavenCentral()仓库 - 使用依赖配置:
implementation 'com.facebook.android:facebook-android-sdk:latest.release'
可行解决方案
1. 替换仓库并指定具体SDK版本
JCenter已停止服务,Gradle仍尝试从该仓库拉取依赖导致超时:
- 打开项目级
build.gradle,确保repositories块仅保留mavenCentral(),移除所有jcenter()引用:repositories { google() mavenCentral() } - 打开模块级(
app/build.gradle),将latest.release替换为具体稳定版本(示例为16.2.0,可根据需求选择最新稳定版):implementation 'com.facebook.android:facebook-android-sdk:16.2.0'
2. 清理Gradle缓存
缓存可能残留旧仓库配置,执行以下操作:
- 终端运行:
flutter clean - 删除项目根目录下的
.android/build文件夹 - 进入
android目录,运行:./gradlew clean
3. 检查网络配置
- 确保网络可正常访问MavenCentral,若网络受限,可在
build.gradle中添加国内镜像仓库:repositories { maven { url 'https://maven.aliyun.com/repository/public' } google() mavenCentral() }
4. 升级Gradle版本
旧版Gradle对新仓库支持不佳,升级项目级build.gradle中的Gradle插件版本:
buildscript { dependencies { classpath 'com.android.tools.build:gradle:7.4.2' // 适配的稳定版本 } }
内容的提问来源于stack exchange,提问作者sachin
相关产品推荐
相关产品推荐

