Podfile用途
用于指定一个或多个XCode工程的依赖
Root Options
Podfile文件的整体配置
install!
语法如下:
1 | install! 'cocoapods', |
支持的option-value以及默认值如下:
option | default value | meaning |
---|---|---|
:clean | true | 是否清除Pods文件夹内的无关文件 |
:deduplicate_targets | true | 是否针对有不同subspec的同一pods库生成不同的pods targets |
:deterministic_uuids | true | 是否生成确定的uuid |
:integrate_targets | true | 是否将pods自动集成到项目中,即是否生成那个白色的.xcworkspace文件 |
:lock_pod_sources | true | 在下载pods库的时候是否锁定Podfile文件 |
:warn_for_multiple_pod_sources | true | 对于名字与版本号均相同的pods库是否需要warning |
:share_schemes_for_development_pods | false | 是否共享开发pods的xcode工程 |
:disable_input_output_paths | false | 是否禁用Cocoapods脚本的输入输出路径 |
:preserve_pod_file_structure | false | 是否需要保持pods库的原有结构 |
:generate_multiple_pod_projects | false | 是否需要生成多个Pods.xcodeproj文件 |
:incremental_installation | false | 是否仅重新生成在上次安装之后有改动的target和相关工程 |
:skip_pods_project_generation | false | 是否跳过生成Pods.xcodeproj文件 |
Dependencies
pod
1 | pod 'podName' //安装最新版本 |
:configuration
指定在哪些模式下安装,主要是Debug和Release
1 | pod 'podName', :configuration => 'Release' |
:modular_headers
表示是否使用模块化的header
1 | pod 'podName', :modular_headers => true |
:source
指定搜索的位置
1 | pod 'podName', :source => 'xxxxxx' |
:subspecs
指定要安装的子部分
1 | pod 'podName', :subspecs => 'xxxxxx' |
:path
指定本地地址作为当前pods库的地址
1 | pod 'podName', :path => 'xxxxxx' |
:git
指定git仓库以及相应的分支,或者tag,或者commit
1 | pod 'podName', :git => 'xxx', :branch => 'xxx', :tag => 'xxx', commit => 'xxx' |
p.s. branch默认为master
target
用于指定不同target的具体的pods库
1 | target 'targetName' do |
target的pods库的继承
1 | target 'ShowsApp' do |
script_phrase
会在运行工程的时候运行这个script
1 | script_phase :name => 'HelloWorldScript', :script => 'echo "wwww" > test.txt' |
abstract_target
和target的不同点在于abstract_target所指定的target实际上不存在,继承关系类似。
1 | abstract_target 'Shows' do |
inherit!
主要有三种选项:
1 | inherit! :search_paths // 只继承搜索路径 |
Target Configuration
platform
1 | platform [平台名称], [目标版本] |
平台名称有,:ios, :osx, :tvos, :watchos
project
指定这个podfile对应的project,如果没有显式指定,并且当前目录下只有一个project则使用这个project
1 | project [工程名称], [build_configuration] |
其中build_configuration用于指定构建项目方式的参数,值有:debug和:release两个
举例:
1 | project 'Aweme', 'TikTokDebug' => :debug, 'TikTokInhouseDebug' => :debug, 'MusicallyInhouseDebug' => :debug, 'MusicallyDebug' => :debug |
如果未指定值,则默认值为:release
inhibit_all_warnings!
添加这一行可以省略所有pods中的warning,也可以对单独的pod进行设置,如下:
1 | pod 'podName', :inhibit_warnings => false // 可以用于exclude from inhibit_all_warnings! |
use_frameworks!
添加这一行表明应当使用Static Library而不是Frameworks(去掉感叹号则表示相反的意思),有参数用于指定使用静态链接还是动态链接
1 | use_frameworks! :linkage => :dynamic |
Workspace Configuration
workspace
指定这个podfile对应的workspace,如果没有显式指定,并且当前目录下只有一个workspace则使用这个workspace
1 | workspace 'workspaceName' |
Source
指定来源,如果指定了新的来源,则必须显式加上Cocoapods的来源,即:
1 | source 'https://github.com/artsy/Specs.git' |
##Hooks
plugins
语法为:
1 | plugin 'pluginName', [参数对] |
举例:
1 | plugin 'cocoapods-keys', :keyring => 'Eidolon' |
pre_install和post_install
用于指定安装前后的hook操作,传入的参数为Pod::Installer
举例:
1 | post_install do |installer| |
pod install和pod update的区别
pod install是只会安装新的pods库和卸载旧的pods库,pod update如果不指定对象,则会在pod install的基础上再进行所有库的更新检查(包括降级检查),如果指定库名,则只会对该库进行该操作。