获取 Cocoapods 安装错误,同时发出命令 "npx react-native init MyProject"

Getting Cocoapods installation error, while issuing command "npx react-native init MyProject"

我是新手 react-native 我已经通读了入门文档并使用以下命令安装了 cocoapods:

sudo gem install cocoapods

这是成功的。我正在使用下面提到的环境:

Mac OS 10.14.6
Xcode 11.3.1
CLT 11.3.1
Ruby 2.6.5
Cocoapods 1.9.3

现在,当我 运行 命令 npx react-native init MyProject 时,我得到以下日志:

✔ Downloading template
✔ Copying template
✔ Processing template
✖ Installing CocoaPods dependencies (this may take a few minutes)
✖ Installing CocoaPods dependencies (this may take a few minutes)
error Error: Failed to install CocoaPods dependencies for the iOS project, which is required by this template.
Please try again manually: "cd ./MyProject/ios && pod install".
CocoaPods documentation: https://cocoapods.org/

再次,我在 ios 目录中尝试了命令 pod install,得到以下错误:

Analyzing dependencies
Fetching podspec for `DoubleConversion` from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`
Fetching podspec for `Folly` from `../node_modules/react-native/third-party-podspecs/Folly.podspec`
Fetching podspec for `glog` from `../node_modules/react-native/third-party-podspecs/glog.podspec`
dyld: lazy symbol binding failed: Symbol not found: _ffi_prep_closure_loc
  Referenced from: /Users/soumisar/.rvm/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle
  Expected in: /usr/lib/libffi.dylib

dyld: Symbol not found: _ffi_prep_closure_loc
  Referenced from: /Users/soumisar/.rvm/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle
  Expected in: /usr/lib/libffi.dylib

Abort trap: 6

请让我知道哪里出错了。

所以我找到了解决方案:

问题出在 ruby 中的这个 glog 库(如上面的错误日志中所述)。在 Internet 上搜索了有关该问题的信息 Symbol not found: _ffi_prep_closure_loc

出现这种情况是因为在 MacOS 10.14 中,ffi 库可能是旧的,必须更新。安装最新ffi库的命令是

gem inst ffi -- --disable-system-libffi

这个命令对我有用。

或者另一个解决方案可能是升级 MacOS 10.15(Catalina)

有关此问题的更多详细信息,请参阅以下内容link

https://gitmemory.com/issue/ffi/ffi/791/645594873