使用 Apple Silicon 的 Mac 别用 gen 来安装 CocoaPods

新买的 Mac Studio 还未安装过 CocoaPods,因为最近开发的项目都是用 Swift Package Manager。目前仍然有很多项目是使用 CocoaPods,今天从 GitHub 上 Clone 了一个 App 就是使用 CocoaPods。我的一般都是直接安装官网的方式去安装,没必要百度和 Google,但是安装官网的安装命令 sudo gem install cocoapods 安装,是能安装成功的,但是使用时却报错了:

1
2
3
4
5
6
7
8
9
10
11
12
$ pod install
Analyzing dependencies
Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi/library.rb:275: [BUG] Bus Error at 0x00000001046b4000
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]

-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
for more details.
Don't forget to include the above Crash Report log file in bug reports.

gem 其实就是一个包管理器,相当于 npm,可以通过 gem 命令从https://rubygems.org/ 下载包。

1. 第一想到的就是重装,怀疑是遗漏了什么。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# gan @ ganzhixacstudio in ~ [16:59:22] 
$ sudo gem uninstall cocoapods
Remove executables:
pod, sandbox-pod

in addition to the gem? [Yn] y
Removing pod
Removing sandbox-pod
Successfully uninstalled cocoapods-1.11.3

# gan @ ganzhixacstudio in ~ [16:59:35]
$ pod --version
zsh: command not found: pod

# gan @ ganzhixacstudio in ~ [16:59:42] C:127
$ gem list --local | grep cocoapods

cocoapods-core (1.11.3)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (1.6.3)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.1)
cocoapods-trunk (1.6.0)
cocoapods-try (1.2.0)

# gan @ ganzhixacstudio in ~ [17:00:26]
$ sudo gem uninstall cocoapods-core
Successfully uninstalled cocoapods-core-1.11.3

# gan @ ganzhixacstudio in ~ [17:01:46]
$ sudo gem uninstall cocoapods-deintegrate
Successfully uninstalled cocoapods-deintegrate-1.0.5

# gan @ ganzhixacstudio in ~ [17:01:54]
$ sudo gem uninstall cocoapods-downloader
Successfully uninstalled cocoapods-downloader-1.6.3

# gan @ ganzhixacstudio in ~ [17:02:04]
$ sudo gem uninstall cocoapods-plugins
Successfully uninstalled cocoapods-plugins-1.0.0

# gan @ ganzhixacstudio in ~ [17:02:11]
$ sudo gem uninstall cocoapods-search
Successfully uninstalled cocoapods-search-1.0.1

# gan @ ganzhixacstudio in ~ [17:02:18]
$ sudo gem uninstall cocoapods-trunk
Successfully uninstalled cocoapods-trunk-1.6.0

# gan @ ganzhixacstudio in ~ [17:02:24]
$ sudo gem uninstall cocoapods-try
Successfully uninstalled cocoapods-try-1.2.0

# gan @ ganzhixacstudio in ~ [17:03:29]
$ gem list --local | grep cocoapods

2. 更新 gem

1
2
$ sudo gem update --system
Latest version already installed. Done.

3. 更新 ffi

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ gem list --local | grep ffi      
ffi (1.15.5)
public_suffix (4.0.7)

# gan @ ganzhixacstudio in ~ [17:10:48]
$ gem install ffi
Fetching ffi-1.15.5.gem
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

# gan @ ganzhixacstudio in ~ [17:12:26] C:1
$ sudo gem install ffi
Password:
Building native extensions. This could take a while...
Successfully installed ffi-1.15.5
Parsing documentation for ffi-1.15.5
Done installing documentation for ffi after 3 seconds
1 gem installed

4. 再次安装 CocoaPods

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$ sudo gem install cocoapods -n /usr/local/bin


Fetching cocoapods-core-1.11.3.gem
Fetching cocoapods-deintegrate-1.0.5.gem
Fetching cocoapods-downloader-1.6.3.gem
Fetching cocoapods-plugins-1.0.0.gem
Fetching cocoapods-search-1.0.1.gem
Fetching cocoapods-trunk-1.6.0.gem
Fetching cocoapods-try-1.2.0.gem
Fetching cocoapods-1.11.3.gem
Successfully installed cocoapods-core-1.11.3
Successfully installed cocoapods-deintegrate-1.0.5
Successfully installed cocoapods-downloader-1.6.3
Successfully installed cocoapods-plugins-1.0.0
Successfully installed cocoapods-search-1.0.1
Successfully installed cocoapods-trunk-1.6.0
Successfully installed cocoapods-try-1.2.0
Successfully installed cocoapods-1.11.3
Parsing documentation for cocoapods-core-1.11.3
Installing ri documentation for cocoapods-core-1.11.3
Parsing documentation for cocoapods-deintegrate-1.0.5
Installing ri documentation for cocoapods-deintegrate-1.0.5
Parsing documentation for cocoapods-downloader-1.6.3
Installing ri documentation for cocoapods-downloader-1.6.3
Parsing documentation for cocoapods-plugins-1.0.0
Installing ri documentation for cocoapods-plugins-1.0.0
Parsing documentation for cocoapods-search-1.0.1
Installing ri documentation for cocoapods-search-1.0.1
Parsing documentation for cocoapods-trunk-1.6.0
Installing ri documentation for cocoapods-trunk-1.6.0
Parsing documentation for cocoapods-try-1.2.0
Installing ri documentation for cocoapods-try-1.2.0
Parsing documentation for cocoapods-1.11.3
Installing ri documentation for cocoapods-1.11.3
Done installing documentation for cocoapods-core, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-trunk, cocoapods-try, cocoapods after 2 seconds
8 gems installed

# gan @ ganzhixacstudio in ~ [17:13:04]
$ pod --version
1.11.3

5. 尝试搜索包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ pod search AFNetworking    
/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi/library.rb:275: [BUG] Bus Error at 0x0000000100274000
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]

-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
for more details.
Don't forget to include the above Crash Report log file in bug reports.

-- Control frame information -----------------------------------------------
c:0036 p:---- s:0222 e:000221 CFUNC :attach
c:0035 p:0258 s:0216 e:000215 METHOD /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi/library.rb:275
c:0034 p:0050 s:0196 e:000195 CLASS /Library/Ruby/Gems/2.6.0/gems/ethon-0.15.0/lib/ethon/libc.rb:17

6. 还是报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ pod search AFNetworking    
/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi/library.rb:275: [BUG] Bus Error at 0x0000000100274000
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]

-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
for more details.
Don't forget to include the above Crash Report log file in bug reports.

-- Control frame information -----------------------------------------------
c:0036 p:---- s:0222 e:000221 CFUNC :attach
c:0035 p:0258 s:0216 e:000215 METHOD /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi/library.rb:275
c:0034 p:0050 s:0196 e:000195 CLASS /Library/Ruby/Gems/2.6.0/gems/ethon-0.15.0/lib/ethon/libc.rb:17

7. 使用 brew 安装 CocoaPods

看来只能 Google 了,在 pod install has bug · Issue #10723 · CocoaPods/CocoaPods 找到了同样的问题。

看来下答案,方法有几个,别随便使用,你得针对你的环境才行啊。

所以我使用 https://github.com/CocoaPods/CocoaPods/issues/10723#issuecomment-1117528801 的回答操作。
他的回答,翻译过来就是:

我在新的 M1 mac 上构建 ionic 6 应用程序时遇到了这个问题。运行npx cap sync 抛出此错误。

arch -x86_64此线程中的其他解决方案建议通过命令前缀强制使用 Rosetta 2 / x86 模式。

对我来说,最好的解决方案就是通过homebrew安装 cocoapods :

1
brew install cocoapods

这是因为homebrew 的 cocoapods 公式现在提供了对本地 Apple Silicon 构建的 cocoapods 的支持,上面的命令会为您安装它。

因为使用 Rosetta 在模拟器上会引入其他错误。

使用 brew 安装,需要终端出墙,否则下载 libyaml 会失败。

1
2
3
4
5
6
7
8
9
10
11
12
13
$ export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890

# gan @ ganzhixacstudio in ~ [17:26:04]
$ curl google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

# gan @ ganzhixacstudio in ~ [17:26:07]
$ brew install cocoapods

使用 Apple Silicon 的 Mac 别用 gen 来安装 CocoaPods

https://ganzhixiong.com/p/375a1063/

Author

干志雄

Posted on

2022-08-15

Updated on

2022-08-15

Licensed under

Comments