我有一个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电脑还为时过早。有没有办法暂时解决这个问题?


当前回答

TL; diana:

使用Homebrew / rbenv / RVM安装自己的Ruby版本(例如brew Install Ruby) 将它和gems二进制文件添加到您的PATH中,并确保新版本与ruby一起使用(如果安装了homebrew,应该是/opt/homebrew/opt/ruby/bin/ruby,而不是/usr/bin/ruby) 使用sudo gem安装CocoaPods(确保ethon至少是0.13.0版本) 运行pod安装

详细的回答:

所有建议使用Rosetta / arch -x86_64的答案都是变通方法,并不能完全解决RbConfig和通用二进制文件工作方式所带来的真正问题。

require 'rbconfig'

OSVERSION = RbConfig::CONFIG['host_os']
ARCH = RbConfig::CONFIG['arch']
HOSTCPU = RbConfig::CONFIG['host_cpu']
BUILDCPU = RbConfig::CONFIG['build_cpu']
TARGETCPU = RbConfig::CONFIG['target_cpu']

puts "OS: #{OSVERSION}"
puts "Arch: #{ARCH}"
puts "Host CPU: #{HOSTCPU}"
puts "Build CPU: #{BUILDCPU}"
puts "Target CPU: #{TARGETCPU}"

如果你用macOS附带的通用二进制在包含此代码的文件上调用ruby,你将在M1 Mac上得到以下结果:

OS: darwin20
Arch: universal-darwin20
Host CPU: x86_64
Build CPU: x86_64
Target CPU: universal

正如您所看到的,RbConfig是为«universal»CPU编译的,但是是用x86 CPU构建的。生成的文件(见/System/Library/Frameworks/ ruby .framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/rbconfig.rb)使用了主机CPU的无效信息。

由于ffi使用来自RbConfig的信息(参见https://github.com/ffi/ffi/blob/dfae59e293974efaa7b4d414e5116d7a2187a06e/lib/ffi/platform.rb#L61和https://github.com/ffi/ffi/blob/e3f2cf9b82055709ddbeecbf77810f43438c4b64/spec/ffi/fixtures/compile.rb#L11),我们最终得到OP的错误消息。

因此,解决方案是通过使用Homebrew、rbenv或RVM来获得一个专门为arm64构建的Ruby版本。

自制程序:

Execute brew install ruby Add export PATH=/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.0.0/bin:$PATH to your .zshrc (you can find your Homebrew installation directory with $(brew --prefix) if needed) Execute source ~/.zshrc or restart your shell Make sure you are using the correct ruby binary by executing which ruby (should be $(brew --prefix)/opt/ruby/bin/ruby) Install CocoaPods with sudo gem install cocoapods Make sure you are using the correct pod binary by executing which pod (should be $(brew --prefix)/lib/ruby/gems/3.0.0/bin/pod) Make sure ethon is version 0.13.0 or more with gem info ethon, otherwise run sudo gem install ethon Run pod install

Ruby默认情况下不会随未来的macOS版本一起发布

此外,应该注意的是,ruby仍然只包含在macOS中«与遗留软件兼容»,这可以通过运行irb -v来证明,所以这可能是一个安装自己版本的好机会:

警告:为了兼容性起见,macOS中包含了此版本的ruby 使用遗留软件。在macOS的未来版本中,ruby运行时 默认情况下不可用,可能需要您安装 额外的包。 Irb 1.0.0 (2018-12-18)

来源:

https://betterprogramming.pub/ruby-on-apple-silicon-m1-macs-fb159849b2f5 https://github.com/ffi/ffi/issues/870

其他回答

现在有一个“更好/更容易?”的方法来使用自制软件,如果你已经安装了自制软件,只要运行就可以了

brew install cocoapods

这将安装ruby和利比亚aml作为先决条件,到目前为止,这是最直接的方法(也是最有可能被推荐的方法)。

对于更新pod,也许有人会帮助:

安装ffi后:

sudo arch -x86_64 gem install ffi

更新附件

arch -x86_64 pod update

我已经为这个解决方案为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

这就是我在M1中解决问题的方法。有人可能会得到帮助。

来自系统首选项。用户&组。设置登录shell为

   /bin/bash 

然后关闭终端并重新打开它。运行此命令

sudo gem install -n /usr/local/bin cocoapods -v 1.8.4

希望这能起作用。

这对我来说很有用,试着在Mac M1上创建应用

首先进入你的应用程序文件夹

选择终端应用程序->获取信息->选择运行rosseta

//如果你试图通过xcode构建应用程序 对xcode应用重复上述步骤

注意:在这样做时,请确保您的终端和代码是关闭的。

现在运行终端切换到project_folder/ios

运行以下显示的命令

sudo gem install cocoapods

sudo gem install ffi

sudo arch -x86_64 gem install ffi