2020年11月11日,苹果正式发布第一款用于Mac的自研电脑芯片M1。由于ARM架构的原因,目前还有相当一部分未升级ARM架构支持的Mac软件无法在M1芯片的Mac电脑上运行。如果你的应用是通用型的应用出现不兼容问题可以「勾选使用 Rosetta 打开」(Intel芯片默认方式)方式运行程序。
最近公司刚给配了一个新款的Mac mini,是2020款搭载苹果自研芯片M1的电脑。在安装开发环境时出现了一些问题:
Cocoapds 能够使用 ruby 正常安装,但是master源为0。使用新版安装方式cd ~/.cocoapods/repos
提示无此路径。打开文件夹也没有找到.cocoapods
文件,但是同目录下竟然多出了一个master文件夹。
显示隐藏文件
defaults write com.apple.finder AppleShowAllFiles -boolean true;killall Finder
隐藏文件
defaults write com.apple.finder AppleShowAllFiles -boolean false;killall Finder
也可以在空白桌面或访达中按下快捷键Command + Shift + .
,网上有很多方法,大家可自行百度。
执行pod install
会出错
### Error
LoadError - dlsym(0x7ff8aa0382f0, 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'
...
/usr/local/bin/pod:23:in `load'
/usr/local/bin/pod:23:in `<main>'
――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
[!] Oh no, an error occurred.
Search for existing GitHub issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=dlsym%280x7ff8aa0382f0%2C+Init_ffi_c%29%3A+symbol+not+found+-+%2FLibrary%2FRuby%2FGems%2F2.6.0%2Fgems%2Fffi-1.13.1%2Flib%2Fffi_c.bundle&type=Issues
If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new
Be sure to first read the contributing guide for details on how to properly submit a ticket:
https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md
Don't forget to anonymize any private data!
Looking for related issues on cocoapods/cocoapods...
Found no similar issues. To create a new issue, please visit:
https://github.com/cocoapods/cocoapods/issues/new
然后也给出了解决方案,让去GitHub上找答案。
GitHub上也解释了原因
Currently, libffi +Ruby v2.6.0 seems to have some issues with Apple's DTK. Multiple development tools, including Homebrew (ref Homebrew/brew#7857) seem to have issues working. Some have workarounds, but the core seems to be hidden somewhere in libffi (ref libffi/libffi#571)
I will make sure to keep this issue up to date with fixes from libffi and anything else i can find.
I received my DTK yesterday, and will try to create a fork of libffi and get it to build. As mentioned in the linked ffi issue, support for arm64 already exists, and may just need to be fixed to apply to DTK/macOS devices. Assuming I can get it to work, I will also create a fork for CP with the working version of libffi and try to get it to build.
目前,libffi +Ruby v2.6.0似乎与苹果的DTK有一些问题。多种开发工具,包括Homebrew(参考Homebrew/brew#7857)似乎有问题工作。有一些变通方法,但核心似乎隐藏在libffi的某个地方(参考libffi/libffi#571)
我将确保通过libffi和我能找到的任何修复程序来更新这个问题。
我昨天收到了我的DTK,并将尝试创建一个libffi的分叉,并让它构建。正如在链接的ffi问题中提到的,对arm64的支持已经存在,可能只需要修复以应用于DTK/macOS设备。假设我可以让它工作,我还将用libffi的工作版本为CP创建一个分支,并尝试构建它。
最终解决方案如下:
打开访达->应用->实用工具->终端->右键点击终端->显示简介->勾选使用 Rosetta 打开,关闭终端,重新打开。
执行安装命令
sudo gem install cocoapods
sudo gem install ffi
也可以尝试其他方案,点击这里查看更多解决方案。
2021.02.27
用Xcode打包的时候出现错误 IPA processing failed
打开访达->应用->Xcode->右键点击Xcode->显示简介->勾选使用 Rosetta 打开,关闭Xcode,重新打开。
现在可以正常打包了!
如果没有Rosetta环境,可以尝试终端输入(我新装的电脑是带的,所以没有尝试)
/usr/sbin/softwareupdate --install-rosetta (root permission not required)
/usr/sbin/softwareupdate --install-rosetta --agree-to-license (root permission required)
2021.05.17
cocoapods works natively on the M1/arm64 now.
Make sure to update all your gems, and install a different version of ruby than the one that comes by default on the M1 (which Apple has deprecated anyway).
You can for example use rbenv to manage the ruby version:
brew install rbenv
rbenv install 2.7.2
rbenv global 2.7.2
彩蛋:苹果自带Safari竟然自带翻译功能了,貌似是从Safari14之后才有的。在浏览器的网址右侧刷新按钮旁边。如果你的macOS系统是11并且Safari版本是14,没有这个按钮可以进行如下设置:
打开系统偏好设置->语言与地区->添加首选语言(中文和英文,只有中文是不能显示翻译按钮的),之前的版本好像也要选择地区为其他地区。