1
1

More than 1 year has passed since last update.

Flutterでビルド時にpod installが失敗した時の模索

Last updated at Posted at 2023-04-18

Flutterアプリをビルド(flutter run)した時にpod installで失敗していたので、その時の私の模索記事になります。(あまり当てにならないので参考程度でお願いします)

エラー内容

ビルド時に以下のエラーが発生

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

開発環境

  • Apple Silicon Mac
  • macOS Monterey 12.6
  • Xcode 14.2
  • Android Studio Chipmunk | 2021.2.1 Patch 1
  • Flutter 3.7.11
  • CocaoPods 1.11.3
  • ffi 1.15.5

試したこと

多くの人が遭遇しているエラーになるようで、情報もたくさん出てくるが、(環境により対処法が違うのか)私はどれもうまくいかなかったので、試したことを残しておきます。

Step1. pod repo update

とりあえず、メッセージ通りpod repo updateを実行してみたが、CocoaPodsのバージョンが違うのか、CocoaPodsをインストールしろと言われたので次へ。

$ pod repo update
Updating spec repo `trunk`

CocoaPods 1.12.0 is available.
To update use: `gem install cocoapods`

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.12.0

$ pod --version
1.11.3

Step2. ffiをインストールする

以下の情報を参考にして、ffiをインストールしてみたがダメだった。
私はすでにffiをインストール済みだったので、ダメだったのかもしれない。

$ sudo arch -x86_64 gem install ffi

...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [libffi.la] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all] Error 2
make: *** ["/Users/[User Name]/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/ffi-1.15.5/ext/ffi_c/libffi-arm64-darwin21"/.libs/libffi_convenience.a] Error 2

make failed, exit code 2

Gem files will remain installed in /Users/[User Name]/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/ffi-1.15.5 for inspection.
Results logged to /Users/[User Name]/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/extensions/arm64-darwin-21/3.0.0/ffi-1.15.5/gem_make.out

Step3. Podfile.lockを削除してpod install

結論としては、以下の情報を参考にしながら作業をしていたら、いつの間にかビルドが出来るようになっていた。

手順

  1. iosフォルダ内にある「Podfile.lock」ファイルをどこかに移動する
  2. Android StudioのTerminalから「ios」フォルダに移動してpod install --repo-update
    • pod install --repo-updateは成功したが、Podfile.lockが書き変わってしまった(のでNGかなと諦めモード)
  3. flutter clean
  4. flutter run
    • →とりあえず、pod installは成功したが、GoogleService-Info.plistが見つからないエラー(実際には存在するんだけどな…)
    • →諦めてやり直し
  5. Podfile.lockを元に戻す
  6. flutter clean
  7. flutter run
    • →意味が分からないが、もう一度ビルドしたら成功した!(おそらく何か理由があるのだろうが…)

とりあえず、ビルドは出来たので環境構築は終了。
iOSのシミュレータでもアプリ起動は出来たし、難しいことは後で考えよう。

おまけ. (公式ドキュメント通り)ffiを再インストールする

後から気付いたので試しておりませんが、公式ドキュメントに記載されている方法を試していたら、pod installは成功していたのかな?

$ sudo gem uninstall ffi && sudo gem install ffi -- --enable-libffi-alloc

Note: The default version of Ruby requires sudo to install the CocoaPods gem. If you are using a Ruby Version manager, you might need to run without sudo.
Additionally, if you are installing on an Apple Silicon Mac, run the command:

$ sudo gem uninstall ffi && sudo gem install ffi -- --enable-libffi-alloc

1
1
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
1
1