BitriseでCocoaPodsのインストールが失敗する

React NativeのビルドにBitriseを使っているだけど、久しぶりにビルドしたらios向けに定義しているworkflowのRun CocoaPods installで失敗するようになってしまった。

具体的には以下のような感じで失敗している。

cocoapods version:
$ pod "_1.12.1_" "--version"
/Users/vagrant/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-7.1.1/lib/active_support/core_ext/array/conversions.rb:108:in `<class:Array>': undefined method `deprecator' for ActiveSupport:Module (NoMethodError)
Did you mean?  deprecate_constant
   from /Users/vagrant/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-7.1.1/lib/active_support/core_ext/array/conversions.rb:8:in `<top (required)>'
  from /Users/vagrant/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
    from /Users/vagrant/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
  from /Users/vagrant/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.12.1/lib/cocoapods.rb:9:in `<top (required)>'
   from /Users/vagrant/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
  from /Users/vagrant/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
    from /Users/vagrant/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.12.1/bin/pod:36:in `<top (required)>'
  from /Users/vagrant/.rbenv/versions/2.7.6/bin/pod:23:in `load'
   from /Users/vagrant/.rbenv/versions/2.7.6/bin/pod:23:in `<main>'
command failed, error: exit status 1

どうやらCocoaPodsが依存しているactivesupportで問題が発生している様子。

調べたところ、activesupportのバージョンが7.1.0になってから発生している模様でIssueも作られていて他の人も同様の状況に陥っているみたい。

github.com

でもローカルでは問題が発生していないし、なんでだろって思ったら単にBitriseの環境ではビルドのたびに毎回新たにRubyのランタイムや依存ライブラリがインストールされていて、そのタイミングでactivesupportの最新版が入ったからみたい。

というわけで試しにローカルにインストールされているGemを更新してactivesupportも最新版にしてpod installを実行したところ見事に同じ状態になった。

一番簡単な直し方はactivesupportのバージョンを7.0.8でインストールすることみたい。

というわけで一度今入っている7.1.1を削除して7.0.8を入れ直してみた。

$ sudo gem uninstall activesupport -v 7.1.1
$ gem install -v 7.0.8

これでpod installを実行したところ問題は解消。

というわけでなんとかBitriseでもactivesupportを7.0.8を指定してインストールできればいいんだけどどうするのがいいのか。

と思ったらドキュメントを見た感じでは普通にGemfileを用意しておけばそれを参照してくれるみたい。

devcenter.bitrise.io

このドキュメントに以下のような記述があった。

If you need a specific version of CocoaPods, make sure you define it either in the Gemfile or the Podfile.

The Step first looks for the cocoapods gem in the Gemfile. If there's no cocoapods gem, the Step uses the CocoaPods version defined in the Podfile. If the version is not defined there either, the preinstalled system version will be used which you can check in the system reports.

これはBitriseのworkflowでインストールするCocoaPodsのバージョンを指定するための説明なんだが、ここにactivesupportのバージョン指定もしておけばいけるんじゃないかという淡い期待。そして今まであまり意識してなかったけど既にプロジェクトのトップディレクトリにGemfileが配置されていた。

というわけでその中身を以下のようにする。

source 'https://rubygems.org'

# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby '3.2.2'

gem "activesupport", "~> 7.0.8"
gem 'cocoapods', '~> 1.13'

ついでに利用するRubyのバージョンも3.2.2にして(それまでは2.7.6を使っていた。古い!)、CocoaPodsも最新の1.13にしておいた。

ちなみに今回は一緒に変更しちゃってるけど、これって問題解消を確認する前にいろいろと一緒に変更してしまうことで別の問題が引き起こされてしまったりして何が問題だったかわからなくなるのであんまりよくないことをやっている。

さて、これでコミットしてBitriseで再度workflowを実行してみる。

Determining required cocoapods version
Searching for Podfile.lock
Found Podfile.lock: /Users/vagrant/git/ios/Podfile.lock
Required CocoaPods version (from Podfile.lock): 1.13.0
Searching for gem lockfile with cocoapods gem
No gem lockfile with cocoapods gem found at: 
Using system installed CocoaPods version
Check selected Ruby is installed
Ruby 3.2.2 is installed
Installing cocoapods
Checking cocoapods 1.13.0 gem
Installing
$ gem "install" "cocoapods" "--no-document" "-v" "1.13.0"
$ rbenv "rehash"
cocoapods version:
$ pod "_1.13.0_" "--version"
1.13.0
Installing Pods
$ pod "_1.13.0_" "install" "--no-repo-update"
Auto-linking React Native modules for target `CrimeNabiMobile`: RNAppleAuthentication, RNBackgroundFetch, RNBackgroundGeolocation, RNCAsyncStorage, RNDateTimePicker, RNFS, RNFastImage, RNGestureHandler, RNGoogleSignin, RNKeychain, RNReanimated, RNSVG, RNScreens, RNSentry, RNSound, RNVectorIcons, TextToSpeech, react-native-camera, react-native-date-picker, react-native-idle-timer, react-native-image-picker, react-native-mapbox-gl, react-native-netinfo, react-native-safe-area-context, react-native-splash-screen, react-native-version-info, and react-native-webview
[Codegen] Generating ./build/generated/ios/React-Codegen.podspec.json
Analyzing dependencies
Fetching podspec for `DoubleConversion` from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`
[Codegen] Found FBReactNativeSpec
/Users/vagrant/git/node_modules/react-native/scripts/react_native_pods_utils/script_phases.rb:50: warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments.
/Users/vagrant/git/node_modules/react-native/scripts/react_native_pods_utils/script_phases.rb:50: warning: Passing trim_mode with the 3rd argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, trim_mode: ...) instead.
Fetching podspec for `RCT-Folly` from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`
Fetching podspec for `boost` from `../node_modules/react-native/third-party-podspecs/boost.podspec`
Fetching podspec for `glog` from `../node_modules/react-native/third-party-podspecs/glog.podspec`
/Users/vagrant/git/node_modules/@react-native-mapbox-gl/maps/react-native-mapbox-gl.podspec:11: warning: already initialized constant Pod::TargetsToChangeToDynamic
/Users/vagrant/git/node_modules/@react-native-mapbox-gl/maps/react-native-mapbox-gl.podspec:11: warning: previous definition of TargetsToChangeToDynamic was here
Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
Downloading dependencies
Installing AppAuth (1.6.0)
Installing CocoaLumberjack (3.7.4)
Installing DoubleConversion (1.1.6)

はい、こんな感じで無事に行けました。Rubyのバージョンも3.2.2で問題なくCocoaPodsも新しい1.13.0が使えてる模様。解決。

ちなみに、ローカルで試した範囲ではRubyのバージョンを新しくしてみても、CocoaPodsをそれまで使っていた1.12から1.13にアップデートとしてみてもこの問題は発生していた。

©Keisuke Nishitani, 2023   プライバシーポリシー