前言
由于项目里业务线很多,集成了很多第三方
pod
库 和 私有
pod
库,整个
pod
project
体积非常大。默认的Xcode 编译行为寻找依赖的project进行编译,并且是并行的。
![](http://narutoyq.cc/resources/xcode-build.png)
我们做了如下改动,加快主工程编译速度:
.去除了主工程对 Pods target的依赖编译
.取消上面两个勾选
.在 Manage Scheme 里勾选了Pods project,以便于可以手动选择 Pods project进行编译
如果对
Pods
库更改了,我们可以手动选择
Pods Scheme
进行编译,然后再编译主工程,这样避免
Pods
不必要编译。
问题
每次pod install
之后,pods scheme 自动消失了,我们找到 xcschememanagement.plist
文件
cd demo/Pods/Pods.xcodeproj/xcuserdata/Green.xcuserdatad/xcschemes
cat xcschememanagement.plist
# 输出
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Pods.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
</dict>
...
可以看到:Pods.xcscheme
isShown
是 false
,这样导致scheme
中没有Pods
。
Pod Install 剖析
我们来看看 CocoaPods
源码
cd /Library/Ruby/Gems/2.0.0/gems/
#这里有很多版本,我们只看0.38.2
当我们执行 pod install
,其实调用到Installer
对象,
#文件位置:`cocoapods-0.38.2/lib/cocoapods/command/project.rb`
#初始化 Installer 对象
def run_install_with_update(update)
installer = Installer.new(config.sandbox, config.podfile, config.lockfile)
installer.update = update
#install 方法
installer.install!
end
end
install!
#文件位置:`cocoapods-0.38.2/lib/cocoapods/installer.rb`文件,
#install 方法
def install!
prepare
resolve_dependencies
#下载依赖
download_dependencies
determine_dependency_product_types
verify_no_duplicate_framework_names
verify_no_static_framework_transitive_dependencies
verify_framework_usage
#合成 pods project
generate_pods_project
integrate_user_project if config.integrate_targets?
perform_post_install_actions
end
download_dependencies
#下载pods 资源
def download_dependencies
UI.section 'Downloading dependencies' do
create_file_accessors
install_pod_sources
run_podfile_pre_install_hooks
clean_pod_sources
end
end
generate_pods_project
#合成 pods project
def generate_pods_project
UI.section 'Generating Pods project' do
prepare_pods_project
install_file_references
install_libraries
set_target_dependencies
#执行Podfile 的post_install 代码块
run_podfile_post_install_hooks
#重新写入pod project,就是在这里修改了所有`