発生したエラー
Flutterで開発中のアプリをiOSシミュレーターにデバッグビルドしようとしたら以下のエラーが発生。
Launching lib/main.dart on iPhone 15 Pro Max in debug mode...
~ 省略 ~
[!] CocoaPods could not find compatible versions for pod "FirebaseAnalytics":
In snapshot (Podfile.lock):
FirebaseAnalytics (= 12.2.0)
In Podfile:
firebase_analytics (from `.symlinks/plugins/firebase_analytics/ios`) was resolved to 12.0.4, which depends on
FirebaseAnalytics (= 12.4.0)
2
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 `FirebaseAnalytics` inside your development pod `firebase_analytics`.
You should run `pod update FirebaseAnalytics` to apply changes you've made.
~ 省略 ~
Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies.
To update the CocoaPods specs, run:
pod repo update
Error running pod install
Error launching application on iPhone 15 Pro Max.
Exited (1).
エラーの詳細
着目するエラー文はこちら:
[!] CocoaPods could not find compatible versions for pod "FirebaseAnalytics":
In snapshot (Podfile.lock):
FirebaseAnalytics (= 12.2.0)
In Podfile:
firebase_analytics (from `.symlinks/plugins/firebase_analytics/ios`) was resolved to 12.0.4, which depends on
FirebaseAnalytics (= 12.4.0)
Flutterパッケージfirebase_analyticsが要求するPodのFirebaseAnalyticsバージョンは 12.4.0 となっているが、ios/Podfile.lockでは 12.2.0 になっていることで依存関係解決に失敗してしまったことが原因のようです。
あと、今回のログのように out-of-date ~ というログが出ているときは、Specsリポジトリをpod repo updateで更新しておきましょう。
解決方法
iOSライブラリとPodfile.lockを消してライブラリを入れ直します。
Flutterプロジェクト直下で以下のコマンドを実行します。
$ flutter clean
$ flutter pub get
$ cd ios
$ rm -rf Pods Podfile.lock
$ pod repo update
$ pod install
これでビルドが通るようになりました。