Flutter项目Pod依赖循环:无法更新Pod版本的解决求助
解决Flutter iOS Pod依赖循环与GoogleMaps升级问题
问题详情
- 卡在Pod依赖循环里,没法更新Pod版本,除了
flutter pub upgrade和flutter pub upgrade --major-versions,想知道其他能彻底清理项目并完成更新的命令 - 需要把GoogleMaps至少升到
v9.0.0,已经按要求把Podfile里的iOS版本改成15了,但还是升不了目标包 - 执行
flutter pub outdated显示传递依赖有更新,但直接升级没用 - 跑
pod install提示GoogleMaps版本不兼容,接着交替执行pod update GoogleMaps和pod update Google-Mobile-Ads-SDK陷入死循环
执行命令后的具体输出如下:
flutter pub outdated输出
$ flutter pub outdated Changing current working directory to: /Users/YOU/Documents/app Showing outdated packages. [*] indicates versions that are not the latest available. Package Name Current Upgradable Resolvable Latest direct dependencies: all up-to-date. dev_dependencies: all up-to-date. transitive dependencies: async *2.11.0 *2.11.0 *2.11.0 2.12.0 characters *1.3.0 *1.3.0 *1.3.0 1.3.1 collection *1.18.0 *1.18.0 *1.18.0 1.19.0 http_parser *4.0.2 *4.0.2 *4.0.2 4.1.0 material_color_utilities *0.11.1 *0.11.1 *0.11.1 0.12.0 meta *1.15.0 *1.15.0 *1.15.0 1.16.0 string_scanner *1.2.0 *1.2.0 *1.2.0 1.3.0 webview_flutter *4.9.0 *4.9.0 *4.9.0 4.10.0 webview_flutter_android *3.16.9 *3.16.9 *3.16.9 4.0.0 transitive dev_dependencies: leak_tracker *10.0.5 *10.0.5 *10.0.5 10.0.7 leak_tracker_flutter_testing *3.0.5 *3.0.5 *3.0.5 3.0.8 lints *5.0.0 *5.0.0 *5.0.0 5.1.0 stack_trace *1.11.1 *1.11.1 *1.11.1 1.12.0 test_api *0.7.2 *0.7.2 *0.7.2 0.7.3 vm_service *14.2.5 *14.2.5 *14.2.5 14.3.0 all dependencies are up-to-date.
pod install报错
$ pod install Analyzing dependencies [!] CocoaPods could not find compatible versions for pod "GoogleMaps": In snapshot (Podfile.lock): GoogleMaps (< 8.0, = 7.4.0) In Podfile: google_maps_flutter_ios (from `.symlinks/plugins/google_maps_flutter_ios/ios`) was resolved to 0.0.1, which depends on GoogleMaps (< 10.0, >= 8.4) You have either: * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`. * changed the constraints of dependency `GoogleMaps` inside your development pod `google_maps_flutter_ios`. You should run `pod update GoogleMaps` to apply changes you've made.
依赖循环报错
$pod update GoogleMaps Updating local specs repositories Analyzing dependencies [!] CocoaPods could not find compatible versions for pod "Google-Mobile-Ads-SDK": In snapshot (Podfile.lock): Google-Mobile-Ads-SDK (= 10.11.0, ~> 10.11.0) In Podfile: google_mobile_ads (from `.symlinks/plugins/google_mobile_ads/ios`) was resolved to 5.2.0, which depends on Google-Mobile-Ads-SDK (~> 11.10.0) You have either: * changed the constraints of dependency `Google-Mobile-Ads-SDK` inside your development pod `google_mobile_ads`. You should run `pod update Google-Mobile-Ads-SDK` to apply changes you've made.
$pod update Google-Mobile-Ads-SDK Updating local specs repositories Analyzing dependencies [!] CocoaPods could not find compatible versions for pod "GoogleMaps": In snapshot (Podfile.lock): GoogleMaps (< 8.0, = 7.4.0) In Podfile: google_maps_flutter_ios (from `.symlinks/plugins/google_maps_flutter_ios/ios`) was resolved to 0.0.1, which depends on GoogleMaps (< 10.0, >= 8.4) You have either: * changed the constraints of dependency `GoogleMaps` inside your development pod `google_maps_flutter_ios`. You should run `pod update GoogleMaps` to apply changes you've made.
解决步骤
1. 彻底清理缓存与冗余文件
先把Flutter和iOS侧的缓存、旧依赖文件全清掉:
# 清理Flutter pub缓存 flutter pub cache clean # 进入iOS项目目录 cd ios # 删除Pod锁定文件、Pods文件夹和生成的工作空间 rm -rf Podfile.lock Pods Runner.xcworkspace # 清理CocoaPods本地缓存和更新仓库 pod cache clean --all pod repo update
2. 强制更新Flutter所有依赖
回到项目根目录,强制更新所有依赖(包括主版本升级):
cd .. # 强制升级所有依赖到最新主版本 flutter pub upgrade --major-versions # 重新获取依赖并生成Pod相关配置 flutter pub get
3. 一次性更新所有Pod依赖
不要再单独更新单个Pod,直接一次性更新所有,跳过旧快照的限制:
cd ios # 一次性更新所有Pod,同时更新仓库 pod update --repo-update
4. 手动指定兼容版本(如果上述步骤无效)
如果自动更新还是冲突,直接在pubspec.yaml里指定兼容的google_maps_flutter和google_mobile_ads版本,比如:
dependencies: google_maps_flutter: ^2.5.0 # 此版本对应GoogleMaps v9+,满足iOS15要求 google_mobile_ads: ^5.3.0 # 确保与GoogleMaps的依赖版本兼容
然后执行:
flutter pub get cd ios pod install --repo-update
5. 验证结果
最后执行以下命令确认依赖是否正常:
# 检查Flutter依赖状态 flutter pub outdated # 验证Pod安装是否成功 cd ios pod install
内容的提问来源于stack exchange,提问作者El Dude
相关产品推荐
相关产品推荐

