CocoaPods: podspec 文件如何配置

日常开发遇到的一些发版和集成问题,很多都跟podspec文件相关。于是整理一下该文件所支持的各种特性。,以备查阅。

podspec 文件简介:
规范描述了Pod库的版本。它包括有关应从何处获取源,使用哪些文件,要应用的构建设置以及其他常规元数据(例如其名称,版本和说明)的详细信息。

下面将从 基本信息、支持的平台、构建配置、文件格式、subspec 等5个方面简单记录下 podspec 文件提功了哪些能力。

以下为简单版,先看看:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

Pod::Spec.new do |s|
s.name = "YouPodName"
s.version = "1.0.1.3"
s.summary = "The SDK tools for hotel, travel."
s.homepage = "http://hushizhi.github.io"
s.license = "All rights reserved"
s.author = { "hushizhi" => "hushizhi@xx.com" }
s.cocoapods_version = '>= 0.36'
s.social_media_url = 'https://twitter.com/cocoapods'

s.platform = :ios, "9.0"
s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.7"
s.source = { :git => "ssh://git@git.github.com/business-ios.git", :tag => s.version }

s.dependency 'AFNetworking', '~> 1.0'
s.dependency 'RestKit/CoreData', '~> 0.20.0'
s.requires_arc = true
s.ios.framework = 'CFNetwork'
s.frameworks = 'QuartzCore', 'CoreData'
s.ios.library = 'xml2'
# s.libraries = 'xml2', 'z'

s.compiler_flags = '-DOS_OBJECT_USE_OBJC=0', '-Wno-format'
s.pod_target_xcconfig = { 'USE_HEADERMAP' => 'NO', 'GCC_TREAT_WARNINGS_AS_ERRORS' => 'YES',
'CLANG_WARN_DOCUMENTATION_COMMENTS' => 'NO',
'CLANG_WARN_DOCUMENTATION' => 'NO',
'CLANG_WARN_STRICT_PROTOTYPES' => 'NO'}
s.prefix_header_file = 'iphone/include/prefix.pch'

#s.prefix_header_content = '#ifdef __OBJC__', '#define RP_APP', '#import <ReactiveCocoa/ReactiveCocoa.h>', '#endif'
s.prefix_header_contents = '#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>'
s.prefix_header_contents = '#import <UIKit/UIKit.h>'

s.source_files = 'Classes/**/*.{h,m}', 'More_Classes/**/*.{h,m}'
s.public_header_files = 'Headers/Public/*.h'
s.private_header_files = 'Headers/Private/*.h'
s.ios.resource_bundle = { 'XXX' => 'XXX/{CommonResources,Resource}/**/*.{xib,storyboard,png,plist,json,js,jpg}' }
s.resource_bundles = {
'MapBox' => ['MapView/Map/Resources/*.png'],
'MapBoxOtherResources' => ['MapView/Map/OtherResources/*.png']
}

s.resource = 'Resources/HockeySDK.bundle'
# s.resources = ['Images/*.png', 'Sounds/*']
s.exclude_files = "Classes/Exclude"
# s.exclude_files = 'Classes/**/unused.{h,m}'

subspec 'Twitter' do |sp|
sp.source_files = 'Classes/Twitter'
# sp.source_files = 'Platform/RN/**/*.{h,m}'
sp.exclude_files = 'Platform/RN/Bridge/Viewed/*.{h,m}'
sp.dependency "Platform/UIFragments"
sp.dependency "Platform/Utils"
s.exclude_files = [ 'Public/SortViewController.{h,m}', 'Tree/ListTableViewCell.{h,m}']
end

s.subspec 'Core' do |cs|
cs.dependency 'RestKit/ObjectMapping'
cs.dependency 'RestKit/Network'
cs.dependency 'RestKit/CoreData'
end

s.subspec 'Level_1' do |sp|
sp.subspec 'Level_2' do |ssp|
end
end

end

是不是有些晦涩难懂,没关系,下面逐一分析一下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |s|

# ----- SDK 基本信息 ------

# SDK 名称
s.name = "YouPodName"
# SDK 版本
s.version = "1.0.1.3"
# SDK 简介描述
s.summary = "The SDK tools for hotel, travel."
# SDK 主页,必须是一个能通过网络访问的页面,只要能访问即可。
s.homepage = "http://hushizhi.github.io"
# s.homepage = 'http://www.example.com'
# 许可证
s.license = "All rights reserved"
# s.license = { :type => 'MIT' , :file => 'MIT-LICENSE.txt' }
# 作者
s.author = { "hushizhi" => "hushizhi@xx.com" }
# s.author = 'Darth Vader' , 'Wookiee'
# 支持的CocoaPods版本
s.cocoapods_version = '>= 0.36'
# 社交链接
s.social_media_url = 'https://twitter.com/cocoapods'

# ------ 支持的平台 ------

# 方式1:平台,可以写ios, osx,watchos,tvos。即表示支持所有平台
# s.platform = :ios
# 支持最低版本
s.platform = :ios, "9.0"

# 方式2:支持多平台支持
s.ios.deployment_target = "9.0"
# s.ios.deployment_target = "5.0"
# s.osx.deployment_target = "10.7"
# s.watchos.deployment_target = "2.0"
# s.tvos.deployment_target = "9.0"
s.source = { :git => "ssh://git@git.github.com/business-ios.git", :tag => s.version }


# ------ 构建配置 -----

# 对其他Pod或“子Pod”的任何依赖
s.dependency 'AFNetworking', '~> 1.0'
s.dependency 'RestKit/CoreData', '~> 0.20.0'

# requires_arc允许您指定使用ARC的source_files。可以是支持ARC的文件,也可以是true,以表示所有source_files都使用ARC。
s.requires_arc = true

# 用户目标需要链接的系统框架列表。
s.ios.framework = 'CFNetwork'
s.frameworks = 'QuartzCore', 'CoreData'

# 用户目标(应用程序)需要链接的系统库列表。
s.ios.library = 'xml2'
# s.libraries = 'xml2', 'z'

# 应传递给编译器的标志列表。
s.compiler_flags = '-DOS_OBJECT_USE_OBJC=0', '-Wno-format'

# 要添加到最终专用 pod目标xcconfig文件的任何标志。
s.pod_target_xcconfig = {
'USE_HEADERMAP' => 'NO',
'GCC_TREAT_WARNINGS_AS_ERRORS' => 'YES',
'CLANG_WARN_DOCUMENTATION_COMMENTS' => 'NO',
'CLANG_WARN_DOCUMENTATION' => 'NO',
'CLANG_WARN_STRICT_PROTOTYPES' => 'NO'
}
# s.pod_target_xcconfig = { 'OTHER_LDFLAGS' => '-lObjC' }

# 前缀头文件的路径,可插入到pod项目的前缀头中。 false指示不应生成默认的CocoaPods前缀头。 true是默认值,表示应生成默认的CocoaPods前缀头。
s.prefix_header_file = 'iphone/include/prefix.pch'

# 任何要插入到pod项目的前缀头文件的内容
#s.prefix_header_content = '#ifdef __OBJC__', '#define RP_APP', '#import <ReactiveCocoa/ReactiveCocoa.h>', '#endif'
s.prefix_header_contents = '#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>'
s.prefix_header_contents = '#import <UIKit/UIKit.h>'


# ------ 文件格式 ------

# 源文件
s.source_files = 'Classes/**/*.{h,m}'
# s.source_files = 'Classes/**/*.{h,m}', 'More_Classes/**/*.{h,m}'

# 公共头文件:需要暴露的.h文件,默认暴露所有
# s.public_header_files = "Classes/**/*.h"
s.public_header_files = 'Headers/Public/*.h'

# 私人头文件:不应暴露给用户项目并且不应用于生成文档的
s.private_header_files = 'Headers/Private/*.h'

# 指定资源,比如xib,图片等资源都是
# s.ios.resource_bundle = { 'XXX' => 'XXX/{CommonResources,Resource}/**/*.{xib,storyboard,png,plist,json,js,jpg}' }
s.resource_bundles = {
'MapBox' => ['MapView/Map/Resources/*.png'],
'MapBoxOtherResources' => ['MapView/Map/OtherResources/*.png']
}

# 资源文件:应复制到目标捆绑包中的资源列表。使用此属性指定的资源被直接复制到APP构建目标,因此Xcode并未对其进行优化。
s.resource = 'Resources/HockeySDK.bundle'
# s.resources = ['Images/*.png', 'Sounds/*']

# 应从其他文件中排除的文件列表。
s.exclude_files = "Classes/Exclude"
# s.exclude_files = 'Classes/**/unused.{h,m}'


# ----- subspec 子Pod ------

subspec 'Twitter' do |sp|
sp.source_files = 'Classes/Twitter'
# sp.source_files = 'Platform/RN/**/*.{h,m}'
sp.exclude_files = 'Platform/RN/Bridge/Viewed/*.{h,m}'
sp.dependency "Platform/UIFragments"
sp.dependency "Platform/Utils"
s.exclude_files = [ 'Public/SortViewController.{h,m}', 'Tree/ListTableViewCell.{h,m}']
end
subspec 'Pinboard' do |sp|
sp.source_files = 'Classes/Pinboard'
end

s.subspec 'Core' do |cs|
cs.dependency 'RestKit/ObjectMapping'
cs.dependency 'RestKit/Network'
cs.dependency 'RestKit/CoreData'
end

s.subspec 'ObjectMapping' do |os|
end

s.subspec 'Level_1' do |sp|
sp.subspec 'Level_2' do |ssp|
end
end

end
--------- 本文结束 感谢您的阅读 ---------
0%
;