在 MacOS 上为 Flutter 安装 cocoapods 的问题

Issue installing cocoapods for Flutter on MacOS

最初,我尝试安装 Ruby 而不是使用 MacOS 上已有的 on 并使用 gem install cocoapods 安装 cocoapods 但这不起作用并且出现错误:

ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

并且还尝试了 sudo gem install -n /usr/local/bin 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.14.2/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf60240306-20262-1w4q438.rb extconf.rb
checking for ffi.h... *** 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.
/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)

对于Ruby我使用的版本:ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19] 当我尝试使用 sudo gem update --system 更新系统时,它显示“已安装最新版本。完成。”

然后我下载了 Homebrew 并尝试安装 cocoapods 但我再次遇到错误

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/xcodeproj
Target /usr/local/bin/xcodeproj
already exists. You may want to remove it:
  rm '/usr/local/bin/xcodeproj'

To force the link and overwrite all conflicting files:
  brew link --overwrite cocoapods

To list all files that would be deleted:
  brew link --overwrite --dry-run cocoapods

Possible conflicting files are:
/usr/local/bin/xcodeproj

然后在遵循另一个 Whosebug 答案的建议后,我使用了 brew link --overwrite cocoapods。但是,现在 XCode 出现问题,iPhone 设备模拟器无法连接 - 未显示任何设备。

我在构建期间遇到此错误:

Showing Recent Messages
/Users/Developer/honours/ios/Flutter/Debug.xcconfig:1: could not find included file 'Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig' in search paths

我不太确定如何解决这个问题,非常感谢任何帮助!

使用 this website, step 4 was incredibly helpful! Then I resolved the issue I had with Xcode not being able to find the xcconfig file by using flutter build ios from this answer 解决了我的问题。通过 运行 flutter build,它告诉我问题是什么以及如何解决它——我需要更改默认签名标识符。