制作自己的Pod公有库和私有库

一、公有库

第一步,创建git仓库

用你自己的GitHub账号创建一个空仓库,名字与你本地项目名字相同,记录git地址

第二步,上传项目,并打tag

将你的本地项目上传到GitHub,并打tag

git add .
git commit -m 'create git'
git remote add origin 远程代码仓库地址
git push origin master
git tag 0.0.1
git push --tags

第三步,创建spec文件并配置

pod spec create XX

文件格式可以参考Podspec
你也可以参考其他人配置的spec文件

第四步,创建LICENSE

这里也可以从其他人项目中直接copy一份,但是要修改Copyright (c)
或者直接从MIT这里copy

  • 第四步完成需要提交一下

第五步,注册Trunk

getting-setup-with-trunk

不想看的命令如下:

$ pod trunk register [email protected] 'Orta Therox' --description='macbook air'

记得修改邮箱地址和名字,和LICENSE一致,你会收到个邮件,有个确认地址,复制到浏览器访问,会提示你ACE!

第六步,检测

pod spec lint XX.podspec --verbose --no-clean --allow-warnings

若没问题会提示XX.podspec passed validation.

这里我遇到几个问题

- ERROR | [iOS] unknown: Encountered an unknown error (/usr/bin/xcrun simctl list -j devices

xcrun: error: unable to find utility "simctl", not a developer tool or in PATH
) during validation.
  • 原因是xcode模拟器找不着报错
  • 解决方法:在终端中继续输入 sudo xcode-select -switch Xcode路径/Contents/Developer 即可
  • 比如我的Xcode路径就在application里,sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. 
  • 这个原因有很多,要根据下面不同的NOTE解决问题,因为我依赖了其他第三方,并且在头文件中引入了
  • 解决方法:改用前向声明方式,或者改用其他方式来解决,最好保证你自己的头文件中引入的只是你本地的头文件

第七步,推送到远程CocoaPods列表

pod trunk push XX.podspec --verbose --allow-warnings

这里一般没问题

第八步,验证

删除本地CocoaPods索引缓存,执行以下命令

pod setup
pod search XX

二、私有库

需要两个git仓库,一个为Specs存放podspec,另一个存放私有库源码。

第一步,创建私有的Specs

pod repo add xxx  giturl

(如:pod repo add Myspecs https://github.com/XXX/MySpecs )

创建完在~/.cocoapods/repos 下会生成一个自己的Spec Repomastercocoapod的。

第二步,创建Pod项目工程,并且有可以访问的项目版本控制地址

$pod lib create privatePod

本地地址在~/Library/Caches/CocoaPods/Pods/External

按照提示选择, 完成后会自动打开工程,打开工程在Finder的位置,找到classes文件夹,把.h .m文件放在此处。然后进到工程内执行pod update,自动会把新文件更新进来。注意不要手动在工程内添加文件,加了也没用。修改工程内的xxxx.podspec 与公有库一样。

保存,按照步骤上传git

1.  git add .
2.  git commit -a -m "xxx"
3.  git remote add origin  XXXX.git
4.  git push origin master 
5.  error: failed to push some refs to '[https://github.com/XXX/privatePodTest](https://github.com/XXX/privatePodTest)'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
6. git pull origin master —-allow-unrelated-histories
7. git add .
8. git commit -s -m "xxx"
9. git push origin master
10. git tag -m "test" "0.1.0" (一定要写)
11. git push —-tags

成功后。

//验证pod库
1. pod lib lint 
 //提交到远程spec repo仓库。
2. pod repo push MySpecs MyLib.podspec

pod lib lint是只从本地验证你的pod能否通过验证
pod spec lint是从本地和远程验证你的pod能否通过验证

  • 出现最多的问题 - ERROR | [iOS] file patterns: The source_files pattern did not match any file.

主要就是tag引起的。修改后要重新打个tag。
使用的时候注意 在podfile内需要加入

//私有spec repo
1.  source '[https://github.com/XXX/MySpecs](https://github.com/XXX/MySpecs)' 
//公有spec repo
2.  source '[https://github.com/CocoaPods/Specs.git](https://github.com/CocoaPods/Specs.git)' 

两个都要加入。

私有库更新后push到git服务器之后先打上tag,然后再修改podspec文件中的版本,最后push到对应的pod repo中

你可能感兴趣的:(制作自己的Pod公有库和私有库)