美文网首页
Cocoapods源码调试

Cocoapods源码调试

作者: 梦里桃花舞倾城 | 来源:发表于2022-04-01 17:14 被阅读0次

下载pod源码

下载地址

工程目录如下

先忽略TestLibrary目录下的Podfile.lock、Pods、TestLibrary.xcworkspace文件

NM1tloXcveDrx3B.png

创建Gemfile文件

新建TestLibrary xcode 工程,并创建一个Podfile文件(不要执行pod install)。

platform :ios, '10.0'

use_frameworks!

target 'TestLibrary' do
    pod 'AFNetworking'
end

Cocoapods源码和Xcode工程放到同一目录下,并在该目录下新建一个Gemfile文件(ps:bundle init

安装bundle(已安装可以忽略)

  • gem install bundler

编写Gemfile

source 'https://rubygems.org'
# 指定本地CocoaPods路径
gem 'cocoapods', path: './CocoaPods' 
# Ruby调试的依赖库
gem 'ruby-debug-ide' 
gem 'debase' 

创建 launch.json

VSCode打开目录文件夹,在根目录下,新建.vscode文件夹,在.vscode文件夹下,新建launch.json文件,目录结构如下所示。

xderk8W6CKJLsfu.png

launch.json中,配置程序启动参数:

{
    "configurations": [
    {
    "name": "Debug CocoaPods Plugin",
    "showDebuggerOutput": true,
    "type": "Ruby",
    "request": "launch",
    "useBundler": true,
    // pod 命令执行的路径。会在该路径下寻找Podfile文件。
    "cwd": "${workspaceRoot}/TestLibrary",
    // 指定使用的pod解释文件。
    "program": "${workspaceRoot}/CocoaPods/bin/pod",
    // 执行的命令参数,在这里执行的是 pod install --verbose
    "args": ["install", "--verbose"]
    }]
}

执行bundle install

  • 创建好工程依赖后,在终端执行bundle install
  • Podfile里面设置一个断点
  • Debug调试(F5)
    7wzRovSxFqrTOmg.png
dbClHmjWz8r5YKJ.png

到此就能够完成调试了

常见问题

[!] No Podfile' found in the project directory.

WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.

    Consider adding the following to ~/.profile:

    export LANG=en_US.UTF-8

.bash_profile或者.zshrc文件里面,添加export LANG=en_US.UTF-8 即可解决这个问题。

如果还不行,请重启终端和vscode

相关文章

网友评论

      本文标题:Cocoapods源码调试

      本文链接:https://www.haomeiwen.com/subject/hhiajrtx.html