参考链接:
https://blog.csdn.net/boring_cat/article/details/73187997
https://www.jianshu.com/p/4685af9dd219
//--------正文-------
一、
cd 到你的工程目录下
使用pod spec create创建.podspec文件
二、
2.1
Pod::Spec.new do |你定义的字段|,如:
Pod::Spec.new do |spec|
Pod::Spec.new do |s|
就是用 spec /s 替代Spec.new的功能;
2.2 详细表
- spec.name = ‘Reachability’ #项目名称
- spec.version = ‘3.1.0’ #项目版本号(更新Pod的时候,这里要对应的修改,不修改会更新不到)
- spec.summary = ‘A short description of 你的项目.’ #项目总结,其实就是一个简单的短描述 ;
- spec.description = <<-DESC # 项目详细描述,描述的文字要多于总结的 否则会报警
- spec.license = { :type => ‘MIT’ } #项目的证书 一开始就要在git 配置好
- spec.homepage = ‘https://github.com/tonymillion/Reachability’ #项目的主页 要求可以访问
- spec.authors = { ‘你的大名’ => ‘你的邮箱@163.com’ } #作者以及邮箱
- spec.source = { :git => ‘https://github.com/tonymillion/Reachability.git‘, :tag => ‘v3.1.0’ } #项目的源代码路径 tag是标签 如果没有写明tag,则默认版本号 。注意:项目的源地址,目前只支持Http\Https, 不支持SSH,其他可见示例。
- spec.module_name = ‘Rich’ #项目模块名称
- spec.ios.deployment_target = ‘9.0’ #iOS最低支持系统版本
spec.osx.deployment_target = ‘10.10’ #OSX最低支持系统版本 - s.static_framework = true #是否是静态库
- spec.ios.framework = ‘UIKit’
spec.osx.framework = ‘AppKit’
13.项目下自己创建一个 include文件夹(如果项目生成的时候就有那就不用创建了,没有就自己建一个),里面需要的文件类型你要写明
- s.subspec 'include' do |ss| # 包含文件
- ss.source_files = ‘项目名/common/*.swift’ #代码所在的路径,写错 lint会报错
- spec.ios.source_files = ‘项目名/ios/.swift’, ‘项目/extensions/.swift’ #依赖的资源文件,依赖多个用逗号隔开
- spec.osx.source_files = ‘项目名/osx/*.swift’
- ss.private_header_files = '项目名/include/*.h' # 头文件
- end
14. 项目下自己创建一个 Classes 文件夹(如果项目生成的时候就有那就不用创建了,没有就自己建一个),里面包含的文件类型需要你写明
- s.subspec 'Classes' do |ss|#
- ss.dependency '项目名/include' #依赖的第三方框架,依赖几个,就要写几个s.dependency
- ss.source_files = '项目名/Classes/*.{h,m}' # 包含工程.h .m的文件
- ss.public_header_files = '项目名/Classes/EMASOCR.h' #包含头文件
- ss.vendored_frameworks = '项目名/Framework/框架名或第三方框架名.framework'#依赖的框架,依赖多个用逗号隔开
- end
15.
- spec.dependency ‘SomeOtherPod1’ #依赖的第三方框架,依赖几个,就要写几个s.dependency
- spec.dependency ‘SomeOtherPod2’
- spec.dependency ‘SomeOtherPod3’
16.
- spec.frameworks = 'AVFoundation', 'CoreMedia', 'AudioToolbox', 'UIKit' # 同12,引用的类库,引用多个逗号隔开
17.
- s.libraries = 'iconv.2.4.0', 'xml2', 'c++' #引用的lib库,如 libc++.tbd 等
end
三、 示例:
Pod::Spec.new do |s|
s.name = "PodLibrary"
s.version = "0.1.0"
#项目总结
s.summary = "My PodLibrary is a repo for UIButton+Positioning assembly."
#项目描述,貌似描述的文字要多于总结的,否则会报警告
s.description = <<-DESC
My Private UIButton+Positioning assembly
* MarkDown format
* It is a nice world!
DESC
#项目的主页,要求可以访问
s.homepage = "https://git.coding.net"
#项目的证书类型,一开始在git 就要配置好
s.license = 'MIT'
s.author = { "gaolong" => "gaolong@alibaba.com" }
#最重要的一部分,项目的源地址,目前只支持Http\Https, 不支持SSH,小编曾经犯了一个低级错误,将这个source指向了以前建立的一个Spec.git,然后一直报"The `PodLibrary.podspec` specification does not validate"的错误,小编又不会调试,所以很丢人的折腾了两个小时。
s.source = { :git => "https://git.coding.net/schiller/MyDemoSpec.git", :tag => "0.1.0" }
s.platform = :ios, '7.0'
s.requires_arc = true
#表示项目的源文件在Pods/Classes文件夹下
s.source_files = 'Pod/Classes/**/*'
s.resource_bundles = {
'PodLibrary' => ['Pod/Assets/*.png']
}
#项目的依赖库等等
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
四、项目文件配置完毕之后
cd 到你的工程目录下 使用以下命令验证(注意一定要有网,不是你们公司内网哟)
$ pod lib lint
如果出现
-> PodLibrary (0.1.0)
PodLibrary passesd validation
说明成功了!
五、 进阶:
- 配置私有组件项目
- 向Spec Repo提交podspec
-
Cocoapods制作
参考链接:https://www.jianshu.com/p/d20467788c02
这篇文章说的很细致了,建议小伙伴们多看几遍;