修改pubspec.yaml依赖无效,Flutter仍调用旧Git仓库
解决Flutter pub get仍拉取旧Git依赖仓库的问题
问题情况
已修改pubspec.yaml中magicmodule的Git仓库地址和提交ref:
修改前配置:
magicmodule: url: https://github.com/wrongrepo/magicmodule path: magicmodule ref: b83b8de832749a30037487c12a33ff3297329830
修改后配置:
magicmodule: url: https://github.com/goodrepo/magicmodule path: magicmodule ref: 76f876fc9dc7678a8763ca876876af733b3b3c7
但执行flutter pub get时,依然尝试访问旧仓库并报错:
$ flutter pub get Resolving dependencies... (3.4s) Git error. Command: `git clone --mirror https://github.com/wrongrepo/magicmodule /Users/ern0/.pub-cache/_temp/dir6jK0GP` stdout: stderr: Cloning into bare repository '/Users/ern0/.pub-cache/_temp/dir6jK0GP'... remote: Repository not found. fatal: repository 'https://github.com/wrongrepo/magicmodule' not found
已尝试flutter pub cache clean、手动编辑pubspec.lock、重新添加依赖等操作,均无效。
解决步骤
1. 确认本地配置和分支正确性
- 执行
git status,确认pubspec.yaml的修改已经提交,且当前处于目标工作分支 - 执行
cat pubspec.yaml | grep -A3 magicmodule,再次验证本地文件里的配置确实是新仓库地址
2. 排查依赖传递或强制覆盖问题
- 执行
flutter pub deps查看完整依赖树,搜索magicmodule,看是否有其他依赖间接引入了旧仓库的版本 - 检查
pubspec.yaml里是否有dependency_overrides节点,里面是否还保留着旧的magicmodule配置
3. 彻底清理缓存并重建依赖
- 直接删除项目根目录的
pubspec.lock文件(不要只编辑,彻底删掉) - 执行
flutter pub cache clean清空pub的本地缓存 - 重启你的IDE(VS Code/Android Studio等),避免IDE缓存了旧的配置信息
- 重新执行
flutter pub get
4. 检查Git子模块配置(如果适用)
如果magicmodule是作为Git子模块引入的:
- 打开项目根目录的
.gitmodules文件,确认其中的url已经更新为新仓库地址 - 执行
git submodule sync同步子模块的配置信息 - 执行
git submodule update --init --recursive更新子模块到最新版本
5. 清理全局缓存残留
- 手动删除
~/.pub-cache目录下与magicmodule相关的缓存文件夹 - 确认没有全局的pub镜像或代理配置干扰依赖拉取
内容的提问来源于stack exchange,提问作者ern0
相关产品推荐
相关产品推荐

