1、创建项目以及配置信息
- 创建框架项目
- 打开终端,项目目录下执行命令
// FrameworkName
pod lib create FrameworkName
//此步骤会从git clone 一份项目框架 ,会有几个问题需要回答 诸如项目的语言类型 、选择测试框架、是否需要UIView 测试界面等问题
//完成后项目会自动打开
2、配置项目信息
- 把framework需要的类文件放到 XXX
/Classes(没有就新建)
目录下 - 把framework需要的资源文件放到
XXX/Assets
目录下 - 项目中有个
.podspec
的文件,它就是配置文件了# # Be sure to run `pod lib lint XXX.podspec' to ensure this is a # valid spec before submitting. # # Any lines starting with a # are optional, but their use is encouraged # To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html # Pod::Spec.new do |s| #pod库 名称 s.name = 'XXX' #pod库 版本 s.version = '0.1.1' #详细介绍 s.summary = 'A short description of XXX.' # This description is used to generate tags and improve search results. # * Think: What does it do? Why did you write it? What is the focus? # * Try to keep it short, snappy and to the point. # * Write the description between the DESC delimiters below. # * Finally, don't worry about the indent, CocoaPods strips it! s.description = <<-DESC TODO: Add long description of the pod here. DESC //主页 s.homepage = 'https://github.com/XXX/xxx' # 截图 # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' s.license = { :type => 'MIT', :file => 'LICENSE' } # 作者信息 s.author = { 'xx' => 'www@.com' } # git:项目所在路径,这个比较重要。在打包或者拉取pod的时候,都是根据这个路径拉取的 # 如果你只是想打个framework可以填本地路径就行 '/Users/xx/xx/xx' # 如果你想作为pod来用的话,就需要给项目创建个一直能访问的远程仓库了,这个项目默认是没有关联远程仓库的 # tag:对应git中的tag s.source = { :git => 'https://github.com/xxx/xxx.git', :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>' s.ios.deployment_target = '9.0' s.source_files = 'xxx/Classes/**/*' # s.resource_bundles = { # 'YKUtils' => ['xxx/Assets/*.png'] # } # s.public_header_files = 'Pod/Classes/**/*.h' # s.frameworks = 'UIKit', 'MapKit' # 依赖的其他pod s.dependency 'RxSwift' end
打包framework、上传至公共Spec
- 先运行一下,查看是否有问题
-
cd到
Example
文件夹下,执行pod install
,项目会安装我们配置的文件。
写一段代码测试一下。运行并查看运行效果,和预期一致说明没问题了,如果有错误检查配置是否正确、依赖的文件是否都复制到了Classes
和Assets
中。自己慢慢排查吧 -
提交源码并且打上tag,注意这里的tag要和配置文件中
s.source
的tag
一致git add * git commit -a -m 'v0.1.1' git tag -a 0.1.1 -m 'v0.1.1' // 推送代码和tag git push git push --tags //PS 如果项目没有关联到远程项目库需要执行下面的指令关联 //如果你的s.source 的 git是远程仓库的话,需要把代码和tagpush到远程。框架项目默认是没有关联远程仓库的。新建一个空的远程仓库,然后关联一下 // 关联远程仓库 git remote add origin ssh:/xxxx/sss/tttttttt.git git push -u origin master
-
验证类库
-
cd 到项目根目录下
pod lib lint xxx.podspec --only-errors --verbose
- 打包framework
- 使用cocoapods的cocoapods-packager工具进行打包
// 安装cocoapods-packager插件 已经安装可以忽略
sudo gem install cocoapods-packager
// 打包静态.a库
pod package BZLib.podspec --library --force
// 打包静态framework库
pod package BZLib.podspec --force
![点击并拖拽以移动 wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==](https://i-blog.csdnimg.cn/blog_migrate/fe5148f458a9b4e7e39a3f0bdb0d143c.png)
- 上传至公共podSpec
- 这里会使用到cocoapod的trunk工具,计算机初次使用的话需要注册一个账号
pod trunk register your@email.com 'xxx' --description='description'
- 你会收到一个验证的邮件,验证完就注册完成了
- 部署库
pod trunk push xxx.podspec
提示成功就大功告成了!