ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin24]
现在CocoaPods要求的 Ruby 环境 >= 2.7。需要安装一个高版本的Ruby环境,安装Ruby版本推荐使用 RVM, 安装比较简单一行命令搞定:
curl -sSL https://get.rvm.io | bash -s stable
安装完成后,可以使用命令安装对应版本的Ruby (这里我直接安装的是3.0.0):
rvm install ruby-3.0.0
直接报错:
ruby-3.0.0 - #compiling - please wait
Error running '__rvm_make -j14',
please read /Users/xxxx/.rvm/log/1732948971_ruby-3.0.0/make.log
There has been an error while running make. Halting the installation.
解决办法:
(1)先检查是否安装 openssl@1.1 , 可以通过 brew list 查看
如果没有安装可以先通过下面的命令安装:
brew install openssl@1.1
如果同时存在 openssl@3 的情况下,需要先执行:
brew link --overwrite openssl@1.1
最后执行下面的命令安装:
rvm install ruby-3.0.0 --with-openssl-dir=`brew --prefix openssl@1.1`
安装完成后,切换到当前安装的版本:
rvm use ruby-3.0.0
配置调试项目
安装VSCode插件
在 VSCode 中,安装 Ruby 插件。
说明:Ruby目前已经废弃(替代方案是 Ruby LSP, 试了一下没弄成功)在VSCode可能无法安装,可以到 Version History 里面手动下载然后通过离线安装的方式使用。
下载 CocoPods 源码
git clone https://github.com/CocoaPods/CocoaPods.git
根据实际需要切换到自己需要的版本:
git checkout `pod --version`
创建 Gemfile 文件
调试 Ruby 主要需要以来两个Ruby库:debase 和 ruby-debug-ide。
source 'https://rubygems.org'
gem 'ruby-debug-ide'
gem 'debase'
gem 'cocoapods', path: './CocoaPods/'
然后执行 bundle install
如果安装 debase/ruby-debug-ide 报错,可以参考 https://github.com/ruby-debug/debase/issues/92 可以使用下面的命令:
gem install debase -v0.2.5.beta2 -- --with-cflags="-Wno-incompatible-function-pointer-types"
gem install ruby-debug-ide -v '0.7.3'
创建 launch.json 文件
创建 .vscode/launch.json 文件,添加如下配置
"configurations": [{
"name": "Debug CocoaPods with Bundler",
"showDebuggerOutput": true, // 输出调试信息
"type": "Ruby", // 告诉VSCode要运行什么调试器
"request": "launch", // "launch"允许直接从VSCode启动提供的程序-或"attach"-允许您附加到远程调试会话
"useBundler": true, // rdebug-ide在内运行bundler exec 将Gemfile里面引用的库加到工程中
"cwd": "${workspaceRoot}/Demo", // 表示工作空间路径,指定一个iOS工程(需要放在当前目录下面)
"program": "${workspaceRoot}/cocoapods/bin/pod", // CocoaPods pod命令对应的路径
"args": ["install"],
"env": {}
找到一个命令,出处可以生成环境变量配置:
printf "\n\"env\": {\n \"PATH\": \"$PATH\",\n \"GEM_HOME\": \"$GEM_HOME\",\n \"GEM_PATH\": \"$GEM_PATH\",\n \"RUBY_VERSION\": \"$RUBY_VERSION\"\n}\n\n"
在终端执行可以得到环境变量配置:
➜ ~ printf "\n\"env\": {\n \"PATH\": \"$PATH\",\n \"GEM_HOME\": \"$GEM_HOME\",\n \"GEM_PATH\": \"$GEM_PATH\",\n \"RUBY_VERSION\": \"$RUBY_VERSION\"\n}\n\n"
"env": {
"PATH": "/Users/xxxx/.rvm/gems/ruby-3.0.0/bin:/Users/xxxx/.rvm/gems/ruby-3.0.0@global/bin:/Users/xxxx/.rvm/rubies/ruby-3.0.0/bin:/Users/xxxx/.nvm/versions/node/v16.17.1/bin:/opt/homebrew/opt/openjdk@11/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Applications/iTerm.app/Contents/Resources/utilities:/Users/xxxx/.rvm/bin:/Users/xxxx/.rvm/bin",
"GEM_HOME": "/Users/xxxx/.rvm/gems/ruby-3.0.0",
"GEM_PATH": "/Users/xxxx/.rvm/gems/ruby-3.0.0:/Users/xxxx/.rvm/gems/ruby-3.0.0@global",
"RUBY_VERSION": "ruby-3.0.0"
(2) 提示缺少 LANG 环境变量配置
WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
Consider adding the following to ~/.profile:
export LANG=en_US.UTF-8
/Users/xxxx/CocoaPods/CocoaPods/lib/cocoapods/config.rb:106: warning: $SAFE will become a normal global variable in Ruby 3.0
Uncaught exception: Unicode Normalization not appropriate for ASCII-8BIT
按照错误提示可以通过添加环境变量 export LANG=en_US.UTF-8 解决。对应在VSCode中可以加入下面的环境变量配置:
"env": {
"LANG": "en_US.UTF-8",
"LANGUAGE": "en_US.UTF-8",
"LC_ALL": "en_US.UTF-8"
完整的 .vscode/launch.json 配置示例如下:
"configurations": [{
"name": "Debug CocoaPods with Bundler",
"showDebuggerOutput": true,
"type": "Ruby",
"request": "launch",
"useBundler": true,
"cwd": "${workspaceRoot}/Demo",
"program": "${workspaceRoot}/cocoapods/bin/pod",
"args": ["install"],
"env": {
"PATH": "/Users/xxxx/.rvm/gems/ruby-3.0.0/bin:/Users/xxxx/.rvm/gems/ruby-3.0.0@global/bin:/Users/xxxx/.rvm/rubies/ruby-3.0.0/bin:/Users/xxxx/.nvm/versions/node/v16.17.1/bin:/opt/homebrew/opt/openjdk@11/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Applications/iTerm.app/Contents/Resources/utilities:/Users/xxxx/.rvm/bin:/Users/xxxx/.rvm/bin",
"GEM_HOME": "/Users/xxxx/.rvm/gems/ruby-3.0.0",
"GEM_PATH": "/Users/xxxx/.rvm/gems/ruby-3.0.0:/Users/xxxx/.rvm/gems/ruby-3.0.0@global",
"RUBY_VERSION": "ruby-3.0.0"
"LANG": "en_US.UTF-8",
"LANGUAGE": "en_US.UTF-8",
"LC_ALL": "en_US.UTF-8"
最终整体目录结构如下:
vscode_cocoapods_debug
│── .vscode
│ └── launch.json
├── CocoaPods
├── Demo
├── Gemfile
├── Gemfile.lock
找个地方添加一个断点,运行效果
调试的工程代码:https://github.com/hhtczengjing/vscode_cocoapods_debug
1、RVM问题记录 - Error running ‘__rvm_make -j10‘
2、使用 VSCode debug CocoaPods 源码和插件
3、OpenSSL and Ruby Compatibility Table
4、nicksieger/ruby-3.0.x.patch
5、vscode搭建ruby IDE(mac os)
最近的文章
近期想要测试一段代码,使用Xcode16创建了一个demo工程,在初始化Podfile的时候发现报错。使用的是 pod init 错误信息如下:RuntimeError - `PBXGroup` attempted to initialize an object with unknown ISA `PBXFileSystemSynchronizedRootGroup` from attributes: `{"isa"=>"PBXFileSystemSynchronizedRootGr...…
更早的文章
HarmonyOS NEXT 上的产物有 APP/HAP 两种,其中 APP 上架使用,HAP 用于非上架的场景(企业内部分发和调试包)。 APP 仅用于提交上架,不可以直接安装,只能通过AppStore下载 HAP 非上架发布的场景,可以本地安装,如果是企业发布的应用release模式下的hap无法直接安装 在实际项目中日常提测不可能每次都让开发直接给测试的机器build安装一下,还是需要提供安装包来使用。可以通过 Command Line Tools for ...…