flutter - sudo gem 安装 cocoapods 错误 : Failed to build gem native extension. ?

标签 flutter

Mac big sur ,flutter docker -v
[!] Xcode - 为 iOS 和 macOS 开发 (Xcode 12.0.1)
• Xcode 位于/Applications/Xcode.app/Contents/Developer
• Xcode 12.0.1,构建版本 12A7300
✗ 未安装 CocoaPods。
CocoaPods 用于检索 iOS 和 macOS 平台端的插件代码,以响应您在 Dart 端的插件使用情况。
如果没有 CocoaPods,插件将无法在 iOS 或 macOS 上运行。
更多信息请见https://flutter.dev/platform-plugins
安装:
sudo gem 安装 cocoapods

$ sudo gem install cocoapods
Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
    ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200927-68237-n9jbyc.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
    --with-ffi_c-dir
    --without-ffi_c-dir
    --with-ffi_c-include
    --without-ffi_c-include=${ffi_c-dir}/include
    --with-ffi_c-lib
    --without-ffi_c-lib=${ffi_c-dir}/lib
    --enable-system-libffi
    --disable-system-libffi
    --with-libffi-config
    --without-libffi-config
    --with-pkg-config
    --without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in `try_ldflags'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1832:in `pkg_config'
    from extconf.rb:9:in `system_libffi_usable?'
    from extconf.rb:42:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.13.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.13.1/gem_make.out

最佳答案

我在 Catalina 遇到了同样的问题。我通过安装最新版本的 ruby​​ (2.7.2) 解决了这个问题。
首先安装 Ruby 版本管理器 rvm:

curl -L https://get.rvm.io | bash -s stable
然后安装最新版本的ruby:
rvm install ruby-2.7.2
最后再次尝试安装 cocoapods:
sudo gem install cocoapods

关于flutter - sudo gem 安装 cocoapods 错误 : Failed to build gem native extension. ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64084111/

相关文章:

android - 如何在 Flutter 中获取用户从 Play 商店购买的商品

dart - 在 main 中获取当前上下文

php - 未处理的异常 : FormatException: Unexpected character (at character 1) Flutter

flutter - 如何在 flutter 朔迷离中实现17主机与agora io?

android - Flutter - 禁用状态栏时缺口区域为空白

image - Flutter Navigation 和同时对 dispose() 的要求

regex - 如何使用正则表达式对反斜杠和 ''进行转义和不转义?

在构建中无限调用 Flutter 函数

flutter - 使用flutter选择时如何通过更改颜色和大小来创建圆形按钮

android - Flutter - RevenueCat - 存在凭据问题,请检查底层错误以获取更多详细信息,购买后会出现错误