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

Flutter构建失败:无法解析io.grpc:grpc-core:[1.28.0]求助

问题解决与规避建议

一、当前问题解决步骤

1. 强制依赖从mavenCentral拉取

在项目根目录的build.gradle中添加仓库解析规则,强制拦截jcenter的依赖请求,转向mavenCentral:

allprojects {
    repositories {
        mavenCentral()
        google()
        // 彻底移除jcenter()配置
    }
    configurations.all {
        resolutionStrategy {
            // 强制指定grpc-core的版本并绑定mavenCentral
            force 'io.grpc:grpc-core:1.28.0'
            eachDependency { details ->
                if (details.requested.group == 'io.grpc') {
                    details.useRepository {
                        repository { url = uri('https://repo1.maven.org/maven2/') }
                    }
                }
            }
        }
    }
}

2. 清理缓存后重新构建

执行以下命令清除残留缓存,避免旧依赖干扰:

flutter clean
rm -rf ~/.gradle/caches/
flutter pub get
flutter run

3. 指定兼容的cloud_firestore版本

如果上述方法无效,在pubspec.yaml中锁定一个明确适配mavenCentral的非空安全版本:

dependencies:
  cloud_firestore: ^2.5.4

二、未来规避建议

  • 彻底移除jcenter:在所有build.gradle文件中删除jcenter()配置,统一使用mavenCentral和google()仓库。
  • 定期核查依赖:即使不主动更新,也要关注第三方包的维护状态,及时替换依赖废弃仓库的包。
  • 开启构建日志:用flutter build --debug命令查看依赖解析细节,提前发现异常。
  • 推进空安全迁移:新版本Flutter包基本适配现代仓库体系,迁移后能减少此类兼容问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 23:55:38