LoginSignup
0
0

More than 3 years have passed since last update.

Flutter pod installでエラー undefined method `each_child'

Posted at

背景

FlutterとFirebaseを連携させてiOSシュミレーターでビルドすると、一向に成功しませんでした。。
flutter doctorで確認しても特に問題はなさそうで、、、

かなりの時間ハマってたので、ここに記録することにします:sweat_smile:

環境

MacOS

pubspec.yaml
version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

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: ^0.1.3
  firebase_core: ^1.0.0
  cloud_firestore: ^1.0.0

Rubyのバージョンが問題だった?

こちらをみると、どうやらRubyのバージョンが古いことによって発生するっぽい。。

「なんでRuby??」
と思うだろうが、iOS用のプロジェクトの依存関係マネージャーである「CocoaPods」は Rubyで開発されているため。

どうやってRubyのバージョンを上げるか?

ここが何気に苦労しました。。。

rbenvを使う

こちらを参考に、rbenvでRubyのバージョンを上げることにしました。

rbenv install -l
rbenv install 2.7.1
rbenv global 2.7.1

rbenvは、複数のRubyのバージョンを管理し、プロジェクトごとにRubyのバージョンを指定して使うことを可能としてくれるツールです。
https://mae.chab.in/archives/2612

rbenv install -lでインストールできるrubyのバージョンを確認します。

しかし!!

私の場合はrbenv install 2.7.1が、インストールできるrubyのバージョンに存在しなかったのです!

brew updateでもエラー発生

rbenvでrubyのバージョンを切り替える
:point_up:こちらを参考にbrew updateを実行

MacBook-Pro:~ gen$ brew update
Error: 
  homebrew-core is a shallow clone.
  homebrew-cask is a shallow clone.
To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
These commands may take a few minutes to run due to the large size of the repositories.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!

謎のエラー。。。
ここで30分ぐらい道に迷ったのですが、、、しっかりとエラーメッセージを読むと答えがありました:sweat:

To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow

git -Cから始まるコマンドをそのまま実行するだけでいけました。。

これでrbenv install -lを実行すると、2.7以上のバージョンがリストに表示されました。

rbenvでRubyのバージョンを上げる

rbenv install 2.7.1
rbenv global 2.7.1

cocoapodsを再度インストール

必要なのかはわかりませんが、、念の為再度インストール。
そしてFlutterプロジェクトのiosの階層でpod install

sudo gem install cocoapods

cd ios
pod install

Analyzing dependencies
Pre-downloading: `FirebaseFirestore` from `https://github.com/invertase/firestore-ios-sdk-frameworks.git`, tag `7.3.0`
cloud_firestore: Using Firebase SDK version '7.3.0' defined in 'firebase_core'
firebase_core: Using Firebase SDK version '7.3.0' defined in 'firebase_core'
Downloading dependencies
Installing Firebase (7.3.0)
Installing FirebaseCore (7.3.0)
Installing FirebaseCoreDiagnostics (7.4.0)
Installing FirebaseFirestore (7.3.0)
Installing Flutter (1.0.0)
Installing GoogleDataTransport (8.2.0)
Installing GoogleUtilities (7.2.0)
Installing PromisesObjC (1.2.12)
Installing cloud_firestore (1.0.0)
Installing firebase_core (1.0.0)
Installing nanopb (2.30907.0)
Generating Pods project
Integrating client project
Pod installation complete! There are 4 dependencies from the Podfile and 11 total pods installed.

[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `Runner` to `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` or include the `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` in your build configuration (`Flutter/Release.xcconfig`).

成功!!(多分)

最後に

色々と試行錯誤したので、所々記憶違いで間違えてるかもしれません。。。
発見したら指摘お願いします。:sunglasses:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0