如何在 Mac 上更新 cocoapods for flutter 而不会出现错误?

Boo*_*unz 4 macos rubygems cocoapods flutter

我在 Mac 上将 Flutter 与 Android Studio 结合使用。

\n

有一天(今天),我从命令行运行了“flutter doctor”。

\n

它说我的“cocoapods”不够好。

\n
Doctor summary (to see all details, run flutter doctor -v):\n[\xe2\x9c\x93] Flutter (Channel stable, 2.0.1, on Mac OS X 10.15.7 19H524 darwin-x64, locale en-US)\n[\xe2\x9c\x93] Android toolchain - develop for Android devices (Android SDK version 29.0.2)\n[!] Xcode - develop for iOS and macOS\n    ! CocoaPods 1.8.4 out of date (1.10.0 is recommended).\n        CocoaPods is used to retrieve the iOS and macOS platform side\'s plugin code that responds to your plugin usage on the Dart side.\n        Without CocoaPods, plugins will not work on iOS or macOS.\n        For more info, see https://flutter.dev/platform-plugins\n      To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.\n[\xe2\x9c\x97] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)\n    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.\n[\xe2\x9c\x93] Android Studio (version 4.1)\n[\xe2\x9c\x93] IntelliJ IDEA Community Edition (version 2020.3.2)\n[\xe2\x9c\x93] Connected device (1 available)\n
Run Code Online (Sandbox Code Playgroud)\n

它建议单击此链接以获取有关操作的说明。

\n

说明说要在命令行上运行此命令:

\n
sudo gem install cocoapods\n
Run Code Online (Sandbox Code Playgroud)\n

所以我运行了该命令,但出现错误:

\n
Building native extensions. This could take a while...\nERROR:  Error installing cocoapods:\n    ERROR: Failed to build gem native extension.\n\n    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0/ext/ffi_c\n/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 ./siteconf20210311-2675-ybimov.rb extconf.rb\nchecking for ffi.h... *** extconf.rb failed ***\nCould not create Makefile due to some reason, probably lack of necessary\nlibraries and/or headers.  Check the mkmf.log file for more details.  You may\nneed configuration options.\n\nProvided configuration options:\n    --with-opt-dir\n    --without-opt-dir\n    --with-opt-include\n    --without-opt-include=${opt-dir}/include\n    --with-opt-lib\n    --without-opt-lib=${opt-dir}/lib\n    --with-make-prog\n    --without-make-prog\n    --srcdir=.\n    --curdir\n    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)\n    --with-ffi_c-dir\n    --without-ffi_c-dir\n    --with-ffi_c-include\n    --without-ffi_c-include=${ffi_c-dir}/include\n    --with-ffi_c-lib\n    --without-ffi_c-lib=${ffi_c-dir}/lib\n    --enable-system-libffi\n    --disable-system-libffi\n    --with-libffi-config\n    --without-libffi-config\n    --with-pkg-config\n    --without-pkg-config\n/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)\nYou have to install development tools first.\n    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile\'\n    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror\'\n    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile\'\n    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header\'\n    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for\'\n    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone\'\n    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open\'\n    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone\'\n    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open\'\n    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone\'\n    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for\'\n    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header\'\n    from extconf.rb:10:in `system_libffi_usable?\'\n    from extconf.rb:42:in `<main>\'\n\nTo see why this extension failed to compile, please check the mkmf.log which can be found here:\n\n  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.15.0/mkmf.log\n\nextconf failed, exit code 1\n\nGem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0 for inspection.\nResults logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.15.0/gem_make.out \n
Run Code Online (Sandbox Code Playgroud)\n

我尝试根据故障排除指南完全重新安装,如下所示:

\n
sudo gem uninstall cocoapods\nsudo gem install cocoapods\n
Run Code Online (Sandbox Code Playgroud)\n

我不是 C 程序员或系统分析师……只是想学习 Flutter。

\n

更新 cocoapods 的无错误命令是什么?

\n

小智 15

你可以尝试:

brew install cocoapods
Run Code Online (Sandbox Code Playgroud)