0
0

More than 3 years have passed since last update.

create-react-native-moduleのexample/iosのビルドに失敗する

Last updated at Posted at 2020-05-26

現象

create-react-native-moduleを使ってNativeModuleを作成しようとしたところ、iosでビルド失敗してシミュレータが起動しなくなってしまった。

$ create-react-native-module --generate-example Example

実行環境

実行環境は以下です。
- Xode 11.5
- Cocoapods 1.9.1 (from brew)
- react-native 0.62.2
- create-react-native-module 0.19.0

react-native ios ではビルドに失敗して起動しなかったが、Xcodeではビルドしてシミュレータを起動することができた。
Cocoapods側の不具合にでもあるのかなと推測。

修正内容

Yogaに関するエラーが出ていたので、StackOverflowで似たようなことを書いてある記事を探してトライ&エラーで試してみた。
上手くシミュレーターが立ち上がったの解決策のものはCocoapodsの不具合に言及していたコレ↓
https://stackoverflow.com/questions/48705250/react-native-ios-could-not-build-module-yoga-algorithm-file-not-found

POdfileにYogaのヘッダーファイルを
Podfile:

  use_native_modules!

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
  add_flipper_pods!

+  def change_lines_in_file(file_path, &change)
+    print "Fixing #{file_path}...\n"
+
+    contents = []
+
+    file = File.open(file_path, 'r')
+    file.each_line do | line |
+        contents << line
+    end
+    file.close
+
+    File.open(file_path, 'w') do |f|
+        f.puts(change.call(contents))
+    end
+  end

  post_install do |installer|
    flipper_post_install(installer)

+    # https://github.com/facebook/yoga/issues/711#issuecomment-381098373
+    change_lines_in_file('./Pods/Target Support Files/yoga/yoga-umbrella.h') do |lines|
+        lines.reject do | line |
+            [
+            '#import "Utils.h"',
+            '#import "YGLayout.h"',
+            '#import "YGNode.h"',
+            '#import "YGNodePrint.h"',
+            '#import "YGStyle.h"',
+            '#import "Yoga-internal.h"',
+            ].include?(line.strip)
+        end
+    end
+  end
end

target 'example-tvOS' do
  # Pods for example-tvOS

  target 'example-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end
end

後書き

エラーログを取り忘れてたので別プロジェクトを作ってエラーを再現させようとしたが、一度ビルドできるようになるとエラーが発生しなくなってしまった。

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