iOS Cocoapods集成React NatIve報(bào)錯(cuò)

近期使用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成功。

最近我關(guān)閉Shadowsocks,發(fā)現(xiàn)也能pod insatll成功。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容