一、查看官方文档,Podfile是否支持设置工程名?
答案:没有相关选项
二、分析源码
1、找到GEM_HOME
echo $GEM_HOME
2、在GEM_HOME下搜索相关代码
ag Pods
3、找到了关键代码
$GEM_HOME/gems/cocoapods-1.5.3/lib/cocoapods/sandbox.rb
$GEM_HOME/gems/cocoapods-1.5.3/lib/cocoapods/config.rb
4、找到了关键
$GEM_HOME/gems/cocoapods-1.5.3/lib/cocoapods/sandbox.rb
def project_path
root + 'Pods.xcodeproj'
end
$GEM_HOME/gems/cocoapods-1.5.3/lib/cocoapods/config.rb
def sandbox_root
@sandbox_root ||= installation_root + 'Pods'
end
三、利用pre_install编写代码
在Podfile里添加pre_install
pre_install do |installer|
original_sand = installer.sandbox
def original_sand.project_path
return @root + 'BarPods.xcodeproj'
end
puts installer.sandbox.project_path
end
四、测试
执行 pod install 成功修改了工程名