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


当前回答

在MAC M1中,对于任何使用KMM (Kotlin Multiplatform Mobile)的人,但它可能适用于其他,发现它不会在iOS APP的.xcworkspace上创建文件,当使用CocoaPods作为依赖管理器时,首先通过键入来安装CocoaPods

sudo gem install cocoapods

然后导航到你的项目文件夹,现在在iOS文件夹中输入

sudo arch -x86_64 gem install ffi
arch -x86_64 pod install

现在你应该在iOS工作区中找到所有的文件。 如果你有问题

/Users/$name/$directory/$projectName/$iosFolderName/$iosAppName.xcodeproj 
The linked and embedded framework 'Pods_iosApp.framework' is missing one or more architectures required by this target: x86_64.

你需要添加arm64到xCode,点击项目文件夹-> Build Settings ->,搜索Excluded Architectures并添加arm64

其他回答

从2021年1月7日的1.10.1版本开始,CocoaPods现在支持新的M1芯片。

我确实在新依赖项(Firebase)添加到回购后遇到了这个问题。然后能够做sudo arch -x86_64 gem安装ffi,但其他问题仍然存在。

我的解决方案是: 重新克隆回购并再次运行。

安装:Xcode 12.4 Mac M1 react-native 63.4

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

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

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

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

sudo gem install ffi

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

执行以下命令安装所需的ffi: Sudo arch -x86_64 gem安装ffi 代替pod安装使用: Arch -x86_64 pod安装

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