目录
- 一、公有Pod库制作
- 二、私有Pod库制作
- 三、subspec子库的制作
- 四、遇到的坑
一、公有Pod库制作
制作步骤
1. 创建模版库工程
pod lib create ZCLManager
// 你想在什么平台使用??(由于是制作移动端的库,所以输入iOS)
What platform do you want to use?? [ iOS / macOS ]
> iOS
// 你想使用什么语言??(我制作的库是使用ObjectC开发,所以输入ObjC)
What language do you want to use?? [ Swift / ObjC ]
> ObjC
// 您想在库中包含演示应用程序吗?(输入Yes,制作完成时会自动创建一个Example文件,里面是使用demo)
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
// 您将使用哪些测试框架?(暂无)
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> None
// 你想做基于视图的测试吗?(暂无)
Would you like to do view based testing? [ Yes / No ]
> No
// 类前缀
What is your class prefix?
> ZCL
将写好的代码放在Classes文件夹下面,资源文件放在Assets文件夹下面
回到Example文件夹下,执行pod install,进行代码测试
2.修改podspec配置文件
s.frameworks = 'SystemConfiguration','CoreTelephony','QuartzCore','CoreText','CoreGraphics','UIKit','Foundation','CFNetwork','CoreMotion','WebKit'
s.libraries = 'c++','z'
s.vendored_frameworks = 'ALiPayNOUTDID/Classes/AlipaySDK.framework'
s.vendored_libraries = 'xxx-BaseCore/WeiboManager/libWeiboSDK.a'
3.将代码上传到GitHub远程仓库,并打上标签
cd zclmanager
git init
git add .
git commit -m "first commit"
git remote add origin https://gitee.com/zhouchenglong/zclmanager.git
git push -u origin "master"
git tag '1.0.0'
git push --tags
// 删除本地tag
gi t tag -d 1.0.0
// 删除远端tag
git push origin :refs/tags/1.0.0
4.pod验证(本地+远程)
--verbose:有些非语法错误是不会给出错误原因的,这个时候可以使用--verbose来查看详细的验证过程来帮助定位错误。
--allow-warnings:表示允许警告。
--use-libraries:表示使用静态库或者是framework,这里主要是解决当我们依赖一些framework库后校验提示找不到库的时候用到。
// 本地验证,不会验证tag
pod lib lint
pod lib lint --verbose --allow-warnings --use-libraries
➜ ZCLManager git:(master) pod lib lint
-> ZCLManager (1.0.0)
- NOTE | xcodebuild: note: Using new build system
- NOTE | xcodebuild: note: Using codesigning identity override: -
- NOTE | xcodebuild: note: Build preparation complete
- NOTE | [iOS] xcodebuild: note: Planning
- NOTE | [iOS] xcodebuild: note: Building targets in dependency order
ZCLManager passed validation.
// 验证远程库
pod spec lint
pod spec lint --allow-warnings --use-libraries
➜ ZCLManager git:(master) pod spec lint
-> ZCLManager (1.0.0)
- NOTE | xcodebuild: note: Using new build system
- NOTE | xcodebuild: note: Using codesigning identity override: -
- NOTE | xcodebuild: note: Build preparation complete
- NOTE | [iOS] xcodebuild: note: Planning
- NOTE | [iOS] xcodebuild: note: Building targets in dependency order
Analyzed 1 podspec.
ZCLManager.podspec passed validation.
5.将.podspec文件发布到公有库中(trunk方式)
// 1、注册账户(邮箱+姓名+描述)
- pod trunk register [email protected] 'zhouchenglong' --description='描述'
// 2、打开邮箱,通过邮件内容验证section
// 3、推送到远程
- pod trunk push ZCLManager.podspec
➜ ZCLManager git:(master) pod trunk push ZCLManager.podspec
Updating spec repo `trunk`
Validating podspec
-> ZCLManager (1.0.0)
- NOTE | xcodebuild: note: Using new build system
- NOTE | xcodebuild: note: Using codesigning identity override: -
- NOTE | xcodebuild: note: Build preparation complete
- NOTE | [iOS] xcodebuild: note: Planning
- NOTE | [iOS] xcodebuild: note: Building targets in dependency order
Updating spec repo `trunk`
--------------------------------------------------------------------------------
Congrats
ZCLManager (1.0.0) successfully published
June 14th, 02:28
https://cocoapods.org/pods/ZCLManager
Tell your friends!
--------------------------------------------------------------------------------
// 查看自己是否注册过trunk
- pod trunk me
➜ ZCLManager git:(master) pod trunk me
- Name: zhouchenglong
- Email: [email protected]
- Since: February 12th, 2019 20:20
- Pods:
- ZCLManager
- Sessions:
- June 9th, 04:22 - October 20th, 02:23. IP: 58.33.152.218 Description:
描述
二、私有Pod库制作
一般用于公司内部组件化开发使用
1.创建模版库工程
2.将代码添加到Classes文件中
3.在Example文件夹下执行pod install,进行代码编译测试
4.修改spec配置文件
5.创建远程代码仓库(ZCLProgressViewHUD) + 远程配置仓库(ZSpec)
6.将代码提交到远程仓库,添加tag
7.验证(本地+远程)
前面步骤同共有库制作
8.推送配置文件
推送配置文件
//添加源地址
pod repo add ZSpec https://gitee.com/zhouchenglong/zspec.git
//将spec推送到远程
pod repo push ZSpec ZCLProgressViewHUD.podspec --allow-warnings --use-libraries
如果名称写错可通过 pod repo remove ZSpec 删除
添加source,执行pod install
source "https://gitee.com/zhouchenglong/zspec.git"
source 'https://github.com/CocoaPods/Specs.git'
三、subspec子库的制作
podspec描述文件配置差异,其他上传操作同上。
四、遇到的坑
错误一
-> ALiPods (0.1.0)
- ERROR | [iOS] unknown: Encountered an unknown error (Unable to find a specification for `AlicloudPush (~> 1.9.9)` depended upon by `ALiPods`
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
) during validation.
- 解决方式
这个错误是AlicloudPush是私有库,需要把source加上
pod lib lint --sources='https://github.com/aliyun/aliyun-specs.git,https://github.com/CocoaPods/Specs.git'
错误二
//在集成alipaysdk的时候,缺少UTDID库,导致Pod库验证过不去。
The following build commands failed:
Ld /Users/zhouchenglong/Library/Developer/Xcode/DerivedData/App-fmcozylxykwdchfpozhxzayfrkxf/Build/Intermediates.noindex/App.build/Release-iphonesimulator/App.build/Objects-normal/i386/Binary/App normal i386 (in target 'App' from project 'App')
- 解决方式
只要测试没问题,直接跳过验证
pod trunk push ALiPayNOUTDID.podspec --skip-import-validation