iOS如何上传自己的sdk到cocoapods并用pod管理

(最近弄了下上传sdk到cocoapods遇到了一些坑下面就是解坑大法。我们就重头开始吧。)

一、在Github上创建存储库(前提是得有一个Github账号,如果没有就注册一个)

1.在你账号的首页的右上方会有新建存储库的按钮

2.点击New reposltory进入创建页面


按自己的需求填写好之后,点击Create repository来创建这个存储库,出现下图所示,说明创建成功了。


3.把项目克隆到本地把,cd 到指定的文件夹 然后$git clone 项目的地址

二、将需要cocoapods进行托管的SDK上传到GitHub存储库上且发布到cocoapods上。

1.将自己的SDK工程拷到之前clone到本地的存储库中。()


2.创建pod 账号

发布到cocoapods上你需要有一个pod 的账号,可以使用pod trunk me 来查看自己的账号信息,如果没有账号的话需要先注册一下:

pod trunk register 987654321@qq.com "jianghu"

邮箱会收到一封邮件

在邮箱中点开链接就可以验证成功

然后在使用pod trunk me就可查看自己的账号了


注册完成了

3.在上传之前,先打个tag标记,然后再验证下podspec文件是否正确

(1) git add * (将代码添加到暂存区)

(2) git commit -m '提交内容' (将代码提交到本地库,并写上简述)

创建tag

git tag '1.0.0'

git push --tags

删除tag

//查看tag

git tag

//删除一个指定的tag,并上传一个空tag到远程tag

git tag -d 1.0.0

git push origin :refs/tags/1.0.0

(5) git push origin master (将本地主干提交到远程服务端)

4.创建podspec文件

使用pod spec create JHBezierPath

完成后会生成一个JHBezierPath.podspec的文件

然后编辑这个文件(文件打开方式:个人觉得直接用xcode打开)

Pod::Spec.new do |s|

  s.name        = "JHBezierPath"    #存储库名称

  s.version      = "1.0.0"      #版本号,与tag值一致

  s.summary      = "这是一个曲线图表"  #简介

  s.description  = "贝塞尔曲线的图表"  #描述

  s.homepage    = "https://github.com/976971956/JHBezierPath"      #项目主页,不是git地址

  s.license      = { :type => "MIT", :file => "LICENSE" }  #开源协议

  s.author            = { "jianghu" => "976971956@qq.com" }  #作者

  s.platform    = :ios, "8.0"                  #支持的平台和版本号

  s.source      = { :git => "https://github.com/976971956/JHBezierPath.git", :tag => "1.0.0" }        #存储库的git地址,以及tag值

  s.source_files  =  "JHBezierPath","*.{h,m}" #需要托管的源代码路径

  s.requires_arc = true #是否支持ARC

end


点坑时刻:容易写错的地方

1.  s.name        = "JHBezierPath"  如果错误的话


解决方案:JHBezierPath是pod spec create JHBezierPath中的JHBezierPath ,说白了就是JHBezierPath.podspec的前缀

2.  s.source      = { :git => "https://github.com/976971956/JHBezierPath.git", :tag => "1.0.0" }    

https://github.com/976971956/JHBezierPath.git存储库的git地址 不是ssh地址

3.  s.source_files  =  "JHBezierPath","*.{h,a}" #需要托管的源代码路径

JHBezierPath就是当前cd的文件夹

"*.{h,m}"是JHBezierPath文件夹下的所有.h.a文件

4.报错:

- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code

-NOTE | xcodebuild: note: Using new build system

-NOTE  | xcodebuild:  note: Building targets in parallel

-NOTE  | xcodebuild:  note: Using codesigning identity override: -

-NOTE  | [iOS] xcodebuild:  note: Planning build

-NOTE  | [iOS] xcodebuild:  note: Constructing build description

-NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')

只要在验证后面加上 --skip-import-validation 验证时跳过验证

如果本地有私有库的话,需要通过 --sources= 追加spec.git 的源去验证才可以

5.超时

    - ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/976971956/ROC_NEO_SDK.git /var/folders/25/qfw4l6212wq59nb0xnzp_qc80000gn/T/d20210311-6118-1ja7klq --template= --single-branch --depth 1 --branch 1.0.1

Cloning into '/var/folders/25/qfw4l6212wq59nb0xnzp_qc80000gn/T/d20210311-6118-1ja7klq'...

fatal: unable to access 'https://github.com/976971956/ROC_NEO_SDK.git/': Operation timed out after 300011 milliseconds with 0 out of 0 bytes received

) during validation.

[!] The spec did not pass validation, due to 1 error.

切换网络,可开个热点。

三.验证Podspec

pod lib lint

1.验证通过后如下图所示



2.发布

输入 pod trunk push --allow-warnings命令来发布到cocoapods上,这可能需要几分钟时间。

3.查找库

pod search JHBezierPath --simple

 --simple是只搜索库名字

# 备注:

如果有不足或者错误的地方还望各位读者批评指正,可以评论留言,笔者收到后第一时间回复。

QQ/微信:976971956/ljh976971956。

简书号:[超级卡布达](https://www.jianshu.com/u/6fdefef8016f)

感谢各位观众老爷的阅读,如果觉得笔者写的还凑合,可以关注或收藏一下,不定期分享一些好玩的实用的demo给大家。

文/超级卡布达(简书作者)

著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容