最近自己亲自搞了一下Pod远程管理,遇到了一些问题,最后解决,同时记录下来,也希望能够帮助在这过程中遇到困难的小伙伴。
环境安装与升级
相信大家早已安装过CocoaPods环境,但是CocoaPods升级很可能大家忽略了,所以在进行podspace远程管理中会遇到报错,这里我们第一步先进行环境配置
这里就不从Cocoapods安装步骤开始介绍了,相信大多数人已安装了,并且很多关于安装的教程,大家可以参考。
这里直接从我们遇到的问题开始说起:
1、首先前提是我们本地已经有Cocoapods,我们为了PodSpace远程管理将它进行升级
pod setup
一直出错:
[!] HSGTEST did not pass validation, due to 5 warnings (but you can use `--allow-warnings` to ignore them).
You can use the `--no-clean` option to inspect any issue.
2、意识到是pod的安装环境出了问题
rvm install 2.4.1
也是一直报错:
Error running 'requirements_osx_brew_libs_install autoconf automake libtool coreutils libyaml readline libksba openssl@1.1',
please read /Users/huangshiguang/.rvm/log/1521267513_ruby-2.4.1/package_install_autoconf_automake_libtool_coreutils_libyaml_readline_libksba_openssl@1.1.log
Requirements installation failed with status: 1.
从报错来看可能是我们的rvm环境也有问题,于是我们继续向下看
1、安装 RVM
//RVM: Ruby Version Manager, Ruby的版本管理器,包括Ruby的版本管理和Gem库管理(gemset)
curl -L get.rvm.io | bash -s stable
2、安装home-brew(切记先安装home-brew,再安装ruby!!)
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
3、继续安装rvm最新版本
$ rvm install 2.4.1
4、升级pod
pod setup
环境搞定之后就可以开始的工作了
制作本地库
pod lib create HSGBase
------------------------------
To get you started we need to ask a few questions, this should only take a minute.
If this is your first time we recommend running through with the guide:
- http://guides.cocoapods.org/making/using-pod-lib-create.html
( hold cmd and double click links to open in a browser. )
What platform do you want to use?? [ iOS / macOS ]
> iOS
What language do you want to use?? [ Swift / ObjC ]
> Swift
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
Which testing frameworks will you use? [ Quick / None ]
> None
Would you like to do view based testing? [ Yes / No ]
> No
Running pod install on your new library.
执行完后会自动打开工程
在ReplaceMe.swift位置
![屏幕快照 2018-03-21 下午5.05.46.png](https://upload-images.jianshu.io/upload_images/4246179-5ba958f97806160e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
1、每次更改代码就要cd到Example下执行pod install,这样才能更新代码并可以在事例项目里使用
2、每个类文件如果想暴露出去,则需要在代码类名前添加修饰符即(public class xxx或者open extension xxx),添加public、open,而extension不能用open修饰所以用plublic修饰。
3、如果已经暴露的类,想暴露里边的函数方法,则也需要在方法 func 前加public
本地库提交到CocoaPods远程仓库
提交源代码到git
1、git remote add origin https://github.com/x x x
2、git push -u origin master
3、git commit -a -m "替换文件"
4、git tag 0.0.1
5、git push origin 0.0.1
将Spec提交到Specs Repo
1、pod lib lint
------------------------------
-> HSGBase (0.1.0)
- WARN | summary: The summary is not meaningful.
- WARN | [iOS] swift: The validator used Swift 3.2 by default because no Swift version was specified. To specify a Swift version during validation, add the `swift_version` attribute in your podspec. Note that usage of the `--swift-version` parameter or a `.swift-version` file is now deprecated.
[!] The spec did not pass validation, due to 2 warnings (but you can use `--allow-warnings` to ignore them).
2、pod lib lint --allow-warnings
3、pod trunk register [xxx@xx.com] name
去邮箱认证即可。
4、pod trunk push HSGBase.podspec --allow-warnings
------------------------------
Validating podspec
-> HSGBase (0.1.0)
- ERROR | [iOS] unknown: Encountered an unknown error ([!]
/Applications/Xcode.app/Contents/Developer/usr/bin/
git clone https://github.comxxxxxxxxxxxxxx
--template= --single-branch --depth 1 --branch v0.1.0
Cloning into '/var/folders/tx/fwfjfxpd7318fs37s78c6q5c0000gn/T/d20160709-15448-1mcnv9t'...
warning: Could not find remote branch v0.1.0 to clone.
fatal: Remote branch v0.1.0 not found in upstream origin
) during validation.
看到关键的一行:fatal: Remote branch v0.0.1 not found in upstream origin
这里因为从远端拉不到v0.1.0branch而引起的报错。
4、git tag 0.1.0
5、git push origin 0.1.0
6、pod trunk push HSGBase.podspec --allow-warnings
成功
🎉 Congrats
🚀 HSGBase (0.1.0) successfully published
📅 March 21st, 01:35
🌎 https://cocoapods.org/pods/HSGBase
👍 Tell your friends!
提交podspec到远端
1、cd到自己的HSGBase文件夹
2、pod repo add https://github.com/huangshiguang/HSGBaseSpec.git
3、pod repo push HSGSpec HSGBase.podspec --allow-warnings
------------------------------
Validating spec
-> HSGBase (0.1.0)
- WARN | summary: The summary is not meaningful.
- WARN | [iOS] swift: The validator used Swift 3.2 by default because no Swift version was specified. To specify a Swift version during validation, add the `swift_version` attribute in your podspec. Note that usage of the `--swift-version` parameter or a `.swift-version` file is now deprecated.
Updating the `HSGSpec' repo
Your configuration specifies to merge with the ref 'refs/heads/master'
from the remote, but no such ref was fetched.
Adding the spec to the `HSGSpec' repo
- [Add] HSGBase (0.1.0)
Pushing the `HSGSpec' repo
本地使用
1·Podfile编辑
#因为我们的库在官方Specs和自己的Specs上都上传了,在这里我们只测试官方的
source 'https://github.com/CocoaPods/Specs.git'
#如果需要测试自己私有的,需要把上传到官方Specs的移除
#source 'https://github.com/huangshiguang/HSGBaseSpec.git'
2、pod install
3、项目中使用
更新库内容
1、首先给你的库添加标签
cd到自己的HSGBase文件夹
git tag 0.2.0
git push origin 0.2.0
2、修改podspec的s.version 和s.source = { :git => 'https://github.com/hs g/HSGBase.git',:tag => "0.2.0" }
3、pod trunk push HSGBase.podspec --allow-warnings
4、到项目里更新到指定版本即可
以上就是我的CocoaPods的实践,作为自己实践的记录,同时也通过此与大家进行交流,谢谢观赏!