添加firebase_storage后CocoaPods依赖冲突问题求助
解决Flutter Firebase依赖版本冲突问题
问题情况
我开发了一款用Firebase Auth做身份验证、Cloud Firestore存储数据的Flutter应用,添加firebase_storage依赖后触发了CocoaPods版本兼容错误:Podfile.lock里的Firebase/Firestore版本是10.3.0,但cloud_firestore 4.4.5要求依赖Firebase/Firestore 10.6.0。执行pod repo update后问题依然存在,相关配置和报错信息如下:
报错信息
[!] CocoaPods could not find compatible versions for pod "Firebase/Firestore": In snapshot (Podfile.lock): Firebase/Firestore (= 10.3.0) In Podfile: cloud_firestore (from `.symlinks/plugins/cloud_firestore/ios`) was resolved to 4.4.5, which depends on Firebase/Firestore (= 10.6.0) 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 `Firebase/Firestore` inside your development pod `cloud_firestore`. You should run `pod update Firebase/Firestore` to apply changes you've made.
pod repo update执行输出
Updating spec repo `trunk` apple@apples-MacBook-Air ios %
pubspec.yaml依赖配置
dependencies: flutter: sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 flutter_facebook_auth: shared_preferences: ^2.0.17 flutter_onboard: ^2.0.0 smooth_page_indicator: ^1.0.0+2 flutter_native_splash: ^2.2.17 url_launcher: ^6.1.9 page_transition: "^2.0.9" permission_handler: ^10.2.0 firebase_auth: any firebase_core: any cloud_firestore: any #####################**SEE HERE!**################################## #without firebase_storage the app work fine #but if i add it to here the error is happens firebase_storage: any file_picker: ^5.2.6 uuid: ^3.0.6 google_sign_in: intl_phone_field: ^3.1.0 notification_permissions: ^0.6.1 image_picker: carousel_slider: age_calculator: get: video_player: flashy_tab_bar2: ^0.0.6 flutter_platform_widgets: ^3.2.0
解决步骤
统一Firebase插件版本,避免
any模糊匹配
把pubspec.yaml中所有Firebase相关依赖的any替换为兼容的具体版本,确保它们对应相同的iOS Firebase SDK版本。比如可以用以下版本组合(均兼容Firebase iOS SDK 10.6.0):firebase_auth: ^4.4.2 firebase_core: ^2.12.0 cloud_firestore: ^4.4.5 firebase_storage: ^11.2.6清理本地依赖缓存和Pod文件
- 执行Flutter清理命令:
flutter clean - 进入ios目录,删除旧的Pod锁文件和Pods文件夹:
cd ios rm Podfile.lock rm -rf Pods - 回到项目根目录,重新拉取依赖:
flutter pub get
- 执行Flutter清理命令:
强制更新Firebase Pod版本
进入ios目录,执行以下命令让CocoaPods直接更新Firebase/Firestore到满足要求的版本:pod update Firebase/Firestore检查Podfile(可选)
打开ios/Podfile,确保没有硬编码的Firebase版本限制语句,如果有直接删除,让CocoaPods自动处理版本兼容。
内容的提问来源于stack exchange,提问作者Yunis Maaruf
相关产品推荐
相关产品推荐

