近期使用Cocoapods集成React Native環(huán)境。
pod "Yoga", :path => "./ReactComponent/node_modules/react-native/ReactCommon/yoga"
pod 'React', :path => './ReactComponent/node_modules/react-native', :subspecs =>[
'Core',
'ART',
'RCTActionSheet',
'RCTAdSupport',
'RCTGeolocation',
'RCTImage',
'RCTAnimation’,
'RCTNetwork',
'RCTPushNotification',
'RCTSettings',
'RCTText',
'RCTVibration',
'RCTWebSocket',
'RCTLinkingIOS',
'DevSupport',
]
pod install之后編譯報(bào)錯(cuò)。
/Users/snorreedwin/Code/entur/entur-clients/native/ios/build/Build/Products/Debug-iphonesimulator/React/React.framework/React
Undefined symbols for architecture x86_64:
"_JSNoBytecodeFileFormatVersion", referenced from:
+[RCTJavaScriptLoader loadBundleAtURL:onProgress:onComplete:] in RCTJavaScriptLoader.o
+[RCTJavaScriptLoader attemptSynchronousLoadOfBundleAtURL:runtimeBCVersion:sourceLength:error:] in RCTJavaScriptLoader.o
"facebook::react::parseTypeFromHeader(facebook::react::BundleHeader const&)", referenced from:
+[RCTJavaScriptLoader attemptSynchronousLoadOfBundleAtURL:runtimeBCVersion:sourceLength:error:] in RCTJavaScriptLoader.o
"facebook::react::customJSCWrapper()", referenced from:
-[RCTDevSettings isJSCSamplingProfilerAvailable] in RCTDevSettings.o
-[RCTDevSettings toggleJSCSamplingProfiler] in RCTDevSettings.o
_RCTNSErrorFromJSErrorRef in RCTJSCErrorHandling.o
-[RCTSamplingProfilerPackagerMethod handleRequest:withResponder:] in RCTSamplingProfilerPackagerMethod.o
"facebook::react::systemJSCWrapper()", referenced from:
-[RCTDevSettings isJSCSamplingProfilerAvailable] in RCTDevSettings.o
-[RCTDevSettings toggleJSCSamplingProfiler] in RCTDevSettings.o
_RCTNSErrorFromJSErrorRef in RCTJSCErrorHandling.o
-[RCTSamplingProfilerPackagerMethod handleRequest:withResponder:] in RCTSamplingProfilerPackagerMethod.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
** BUILD FAILED **
The following build commands failed:
Ld /Users/snorreedwin/Code/entur/entur-clients/native/ios/build/Build/Products/Debug-iphonesimulator/React/React.framework/React normal x86_64
(1 failure)
Installing build/Build/Products/Debug-iphonesimulator/reactnativetidr.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, ":CFBundleIdentifier", Does Not Exist
Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/reactnativetidr.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist
google之后發(fā)現(xiàn)如果是版本0.45=<x<=0.46,則需要增加RCTBatchedBridge,cocoapods中增加BatchedBridge,如果版本>0.46則需要用RCTCxxBridge,增加DoubleConversion, Folly,Glog。
如果mac連上google,則直接pod install直接安裝。
pod "yoga", :path => "./ReactComponent/node_modules/react-native/ReactCommon/yoga"
pod 'React', :path => './ReactComponent/node_modules/react-native', :subspecs =>[
'Core',
'ART',
'CxxBridge',
'RCTActionSheet',
'RCTGeolocation',
'RCTImage',
'RCTAnimation’,
'RCTNetwork',
'RCTPushNotification',
'RCTSettings',
'RCTText',
'RCTVibration',
'RCTWebSocket',
'RCTLinkingIOS',
'DevSupport'
]

Snip20180813_2.png
安裝完成后目錄結(jié)構(gòu)。

Snip20180813_4.png
嘗試另外一種寫法:
#官方Cocoapods的源
source 'https://github.com/CocoaPods/Specs.git'
platform:ios,"8.0"
inhibit_all_warnings!
target 'UseReactNative' do
pod 'DoubleConversion', :podspec => './ReactComponent/node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'Folly', :podspec => './ReactComponent/node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'glog', :podspec => './ReactComponent/node_modules/react-native/third-party-podspecs/glog.podspec'
pod "yoga", :path => "./ReactComponent/node_modules/react-native/ReactCommon/yoga"
pod 'React', :path => './ReactComponent/node_modules/react-native', :subspecs =>[
'Core',
'ART',
'CxxBridge',
'RCTActionSheet',
'RCTGeolocation',
'RCTImage',
'RCTAnimation’,
'RCTNetwork',
'RCTPushNotification',
'RCTSettings',
'RCTText',
'RCTVibration',
'RCTWebSocket',
'RCTLinkingIOS',
'DevSupport'
]
end
pod install之后,目錄結(jié)構(gòu)一致,說明DoubleConversion,Folly,glog這三個(gè)包在React其他podspec文件中有依賴(dependencies),默認(rèn)安裝依賴了。

Snip20180813_5.png
如果不能翻墻,則依賴無法安裝成功。

Snip20180813_6.png
可以在百度云上面下載這四個(gè)文件解壓并新建third-party文件復(fù)制文件夾到其中。

Snip20180813_7.png
重新pod install即可clean & build成功。