LoginSignup
1
2

More than 5 years have passed since last update.

CocoaPods経由でreact-native-configを使うとビルドエラーになる問題の対応方法

Posted at

半分個人用のメモ代わりに残しておく

経緯

Podfileがある時にreact-native-linkした時はPodfileにpodspecが自動的に追記される。
そしてreact-native-configをCocoaPod経由で使おうとするとビルドエラーになった。

issue的にはここらへん
https://github.com/luggit/react-native-config/issues/125

色々思考錯誤した結果以下の方法でいけた。

対応方法

こちらのPRの手順でビルドできるようになった
https://github.com/luggit/react-native-config/pull/329

react-native-configのインストール

$ yarn add react-native-config
$ react-native link react-native-config

Podfileに以下を追記

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == 'react-native-config'
      phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
      phase.shell_script = "cd ../../"\
                           " && RNC_ROOT=./node_modules/react-native-config/"\
                           " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
                           " && export BUILD_DIR=$RNC_ROOT/ios/ReactNativeConfig"\
                           " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"

      target.build_phases << phase
      target.build_phases.move(phase,0)
    end
  end
end

react-native-configの設定を追加

  • project -> Build Settings -> Allの検索欄に「preprocess」を入れて絞り込む
  • Preprocess Info.plist FileYesにする
  • Info.plist Other Preprocessor Flags-traditionalを入れる
  • Info.plist Preprocessor Prefix Fileを以下のパスにする
    • $(SRCROOT)/../node_modules/react-native-config/ios/ReactNativeConfig/GeneratedInfoPlistDotEnv.h
    • CococaPods経由かどうかでここのパス変わるのだろうか :thinking:
1
2
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
2