coapods的方式
1.pods需要先更新一下 pod update
- 錯誤:React Native iOS: Could not build module 'yoga': 'algorithm' file not found
需要在node_modules/react-native/ReactCommon/yoga/yoga.podspec 最后一行添加
spec.public_header_files = 'yoga/Yoga.h', 'yoga/YGEnums.h', 'yoga/YGMacros.h'
參考:https://stackoverflow.com/questions/48705250/react-native-ios-could-not-build-module-yoga-algorithm-file-not-found
3.錯誤:Native module cannot be null
需要添加更多的庫,本人試過之后成功的podfile:
source 'https://github.com/CocoaPods/Specs.git'
react_native_path = '../node_modules/react-native'
platform :ios, '8.0'
target 'XXX' do
# ---------react-----------
pod 'React', :path => react_native_path, :subspecs => [
'Core',
'CxxBridge',
'DevSupport', # 如果RN版本 >= 0.43,則需要加入此行才能開啟開發(fā)者菜單
'RCTText',
'RCTImage',
'RCTNetwork',
'RCTWebSocket', # 這個模塊是用于調試功能的
# 在這里繼續(xù)添加你所需要的模塊
'RCTAnimation',
'RCTBlob',
'RCTActionSheet',
'RCTGeolocation',
'RCTSettings',
'RCTVibration',
'RCTActionSheet',
'RCTPushNotification',
'RCTLinkingIOS',
'ART',
]
# 如果你的RN版本 >= 0.42.0,則加入下面這行
pod 'yoga', :path => react_native_path + '/ReactCommon/yoga'
# Third party deps
pod 'DoubleConversion', :podspec => react_native_path + '/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => react_native_path + '/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => react_native_path + '/third-party-podspecs/Folly.podspec'
# ---------react-----------
end
- .a文件要添加到build phases里面
手動拖工程的方式
會找不到頭文件
除了要添加header search paths
$(SRCROOT)/../node_modules/react-native/React 注意后邊選recursive(遞歸查找頭文件)
還要在edit schemes中設置

image.png
注意react放在前面