我有一个Flutter项目,我试图在iOS上运行。它在我那台基于英特尔(intel)处理器的Mac电脑上运行正常,但在我那台基于苹果(Apple) silicon芯片的M1新Mac电脑上却无法安装pod。

LoadError - dlsym(0x7f8926035eb0, Init_ffi_c): symbol not found - /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi.rb:6:in `rescue in <top (required)>'
/Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi.rb:3:in `<top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Library/Ruby/Gems/2.6.0/gems/ethon-0.12.0/lib/ethon.rb:2:in `<top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Library/Ruby/Gems/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus.rb:2:in `<top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/sources_manager.rb:74:in `cdn_url?'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/sources_manager.rb:36:in `create_source_with_url'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/sources_manager.rb:21:in `find_or_create_source_with_url'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:178:in `block in sources'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:177:in `map'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:177:in `sources'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:1073:in `block in resolve_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/user_interface.rb:64:in `section'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:1072:in `resolve_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:124:in `analyze'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:414:in `analyze'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:239:in `block in resolve_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/user_interface.rb:64:in `section'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:238:in `resolve_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:160:in `install!'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/command/install.rb:52:in `run'
/Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:23:in `load'
/usr/local/bin/pod:23:in `<main>'

基于Github的解决方案,我尝试使用rosetta运行Terminal,但问题仍然相同:https://github.com/CocoaPods/CocoaPods/issues/9907#issuecomment-655870749

意识到苹果芯片的mac电脑还为时过早。有没有办法暂时解决这个问题?


当前回答

截至2022年11月。在一台2021年的M1 iMac上做了下面的测试,它成功了。

# uninstall cocoapods
sudo gem uninstall cocoapods

# Optional; unshallow homebrew core
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow

# Install homebrew to right locations; from https://brew.sh/
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add shortcuts as prompted at the end of running the above command
echo '# Set PATH, MANPATH, etc., for Homebrew.' >> $HOME/.bash_profile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> $HOME/.bash_profile
eval "$(/opt/homebrew/bin/brew shellenv)"

# Install cocoapods
brew install cocoapods

# Further, install Vim; taken from https://formulae.brew.sh/formula/vim
brew install vim

其他回答

点击右,打开获取信息菜单 勾选“使用罗塞塔打开”

Sudo gem安装cocoapods

Sudo gem安装ffi

sudo gem update——system //更新ruby

如果不起作用:

安装ruby管理器,我更喜欢rvm

rvm安装:

安装gnupg

gpg——keyserver hkp://pool.sks-keyservers.net——recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB \curl -sSL https://get.rvm.io | bash

不要忘记添加bash配置文件:

导出路径= " $路径:$ HOME /。rvm/bin" #添加rvm到脚本路径(到 export PATH="$GEM_HOME/bin:$PATH" [[-s . “$ HOME /。rvm/scripts/rvm"]] && source "$HOME/。rvm/scripts/rvm" #加载 RVM转换为shell会话作为函数

检查

美元区附些

RVM安装成功后执行此命令

安装新的ruby版本:

$rvm install 3.1.2

选择默认版本:

$rvm—默认使用3.1.2

然后重新启动终端并运行$sudo gem install cocoapods

编辑:我最近禁用了Rosetta, Cocoapods在添加ffi宝石后运行得很好。

对于其他正在为这个问题而挣扎的人来说,我只是找到了解决它的方法。除了在Rosetta中运行终端:

在查找器中右键单击终端 得到信息 打开罗塞塔

我安装了一个宝石,似乎与错误中没有找到的符号有关:

sudo gem install ffi

在这之后,cocoapods就会像预期的那样运行。

我也有同样的问题。我确实发现可可豆的UI应用程序似乎像预期的那样工作。

上面所有的解决方案都是有效的,只是想发布自制和cocoapods支持原生苹果硅芯片,你可以在没有前缀arch -x86_64的情况下运行命令

所以,sudo宝石安装ffi将做的工作。

我已经为这个解决方案为cocoapods安装。

基本上有两种方法来安装可可豆荚。

1. 通过Homebrew安装cocoapods:

brew install cocoapods

2. 通过gem安装cocoapods:

sudo gem install ffi

如果你遇到苹果M1或苹果M2芯片的问题

罗塞塔的第一个终端

右键单击终端应用程序并选择op。 右键点击应用程序,选择“获取信息”。 选中“用Rosetta打开”选项。

您可以执行以下命令:

sudo arch -x86_64 gem install ffi

一旦安装完成,请尝试以下命令:

arch -x86_64 pod install