去年10月的学习笔记,更新复习一下~git
官方文档:CocoaPods Guidesgithub
Podfile 文件:描述工程的依赖库,能够理解为是一份“标准”。
Podfile.lock 文件:记录和追踪已生成的 Pod 版本,里面有以前 pod install 时使用的各个库的版本以及依赖的第三方库版本。能够理解为是一份“历史记录”。xcode
pod install
:从新下载并安装 pods ,版本号从 Podfile.lock 文件中获取,lock 文件中有记录则安装记录版本(不检查更新),无记录则安装 Podfile 指定版本的 podspod update
:无视 Podfile.lock 锁定的版本号,查找并更新到知足 Podfile 中指定版本号要求范围的最新版本 pods
pod update [PODNAME]
,若无 PODNAME 则默认更新 Podfile 中所有 Pods扩展学习:iOS里的动态库和静态库缓存
class Install < Command
include Project
# ...
def run
verify_podfile_exists!
run_install_with_update(false)
end
end
复制代码
#初始化 Installer 对象
def run_install_with_update(update)
installer = Installer.new(config.sandbox, config.podfile, config.lockfile)
installer.update = update
installer.install!
end
复制代码
#install 方法
def install!
prepare // 1.准备工做
resolve_dependencies // 2.解决依赖冲突
download_dependencies // 3.下载依赖文件
determine_dependency_product_types // 4.决定依赖库的类型
verify_no_duplicate_framework_names // 5.验证没有重名的framework
verify_no_static_framework_transitive_dependencies // 6.验证静态库的传递依赖
verify_framework_usage // 7.验证framework的使用
generate_pods_project // 8.生成工程
integrate_user_project // 9.整合用户项目
perform_post_install_actions // 10.执行 install 后的行为
end
复制代码
def download_dependencies
UI.section 'Downloading dependencies' do
create_file_accessors // 3.1 准备沙盒文件访问器
install_pod_sources // 3.2 下载安装Pods依赖库源文件
run_podfile_pre_install_hooks // 3.3 执行Pods依赖库的pre_install的Hook函数
clean_pod_sources // 3.4 根据Config和Installers参数清理Pods的源文件
end
end
复制代码
def generate_pods_project
UI.section 'Generating Pods project' do
prepare_pods_project // 8.1 准备Pods工程
install_file_references // 8.2 安装文件引用
install_libraries // 8.3 安装库
set_target_dependencies // 8.4 为Target设置依赖
run_podfile_post_install_hooks // 8.5 执行Podfile的post_install代码块
write_pod_project // 8.6 执行Project类的Save方法保存配置
share_development_pod_schemes // 8.7 共享依赖库的Target Scheme
write_lockfiles // 8.8 修改Pods工程的LockFile文件
end
复制代码
pod 源码:GitHub - CocoaPods/CocoaPods: The Cocoa Dependency Manager.
源码探究方法参考:pod install和pod update背后那点事 | Startry Blogruby
pod update [PODNAME]
/pod update
,使用 pod update
应慎重。经常使用参数ide
pod cache list [NAME]
:列出本地 pods 缓存记录pod cache clean [NAME]
:删除本地 pods 缓存记录缓存地址:~/Library/Caches/CocoaPods/函数
pod lib create 'xxxxxx'
pod spec create 'xxxxxx'
给项目添加 Podspec 文件pod lib lint xxxxxx.podspec
post
pod trunk push xxxxxx.podspec
查询是否上传成功:pod search xxxxxx
加入其余开发者:pod trunk add-owner 'xxxxxx' '邮箱'
学习
推荐阅读: CocoaPods 结构详解:我所理解的 CocoaPods ui