美文网首页程序员iOS Developer
CocoaPods上传流程及问题解决

CocoaPods上传流程及问题解决

作者: 普通的工具人 | 来源:发表于2017-07-22 11:50 被阅读257次

步骤流程

  • 1.在git上创建新的repository,填写name(你的库名称),勾选readme选项,选择license;

  • 2.将创建的repository clone下来,cd进入该目录下,将自己的库文件和demo放在这个目录下;

  • 3.使用如下命令,在这个目录中创建.podspec文件;
    pod spec create xxx
    xxx是你的库名称

    整个目录结构如下:

Example
  • 4.填写.podspec
    新创建的. podspec里加#的都是注释掉的字段信息,按需填写,有些可以不填;
Pod::Spec.new do |s|
  
  s.name         = "UIImageKit"
  s.version      = "1.0.0"
  s.summary      = "UIImageKit is a library of UIImage class."
  s.description  = <<-DESC 
                    UIImageKit is a library of UIImage class, a simple kit.
                   DESC
  s.homepage     = "https://github.com/Kangqj/UIImageKit"
  s.license      = "MIT"
  s.author       = { "Kangqj" => "kang_qj@sina.cn" }
  s.source       = { :git => "https://github.com/Kangqj/UIImageKit.git", :tag => "#{s.version}" }
  s.source_files = "UIImageKit/**/*"
  s.platform     = :ios
  s.framework  = "UIKit"

end

主要解释两个字段:

source_files:资源文件,当前路径就是库路径,后面再拼接库文件所在的文件夹,

“*” 表示匹配所有文件
“*.{h,m}” 表示匹配所有以.h和.m结尾的文件
“**” 表示匹配所有子目录

s.description:这个描述字段可以不用填写,如果要填写的话,需要将描述写在

<<-DESC 
  xxx
DESC

之间。

  • 5.将项目打tag,push到git上
git tag ‘1.0.0’
git push --tags
  • 6.验证你的.podspec是否有效
    pod spec lint

    验证成功会显示:
    xxx.podspec passed validation.

  • 7.注册CocoaPods
    pod trunk register xxx.podspec youremail.com ‘your name’ —verbose

    完成之后的结果:

[!] Please verify the session by clicking the link in the verification email that has been sent to youremail.com

打开你的邮箱,会收到一封[CocoaPods] Confirm your session的邮件,点击里面的链接,就完成了注册过程。

使用命令:pod trunk me 可以检查是否注册成功,如果返回你注册的信息,说明注册成功了。

  • 8.发布pod
    pod trunk push xxx.podspec

    等待。。。

    Creating search index for spec repo 'master'..`
    Done!
    
成功。

- 9.验证是否真的成功
`pod search xxx`

  能搜索出来自己的库就说明大功告成了^_^
……Y(^_^)Y

- 10.版本更新
  第一个版本上传好了之后,如果后期需要更新,不管是只更新.podspec文件,还是更新工程资源文件,此时如果进行`pod trunk push xxx.podspec `发布的话,会提示错误:

[!] Unable to accept duplicate entry for: xxx

 **应该这样做:**

1.先更新.podspec文件中的 s.version版本号;
2.然后 git tag 打和.podspec中一样的tag,再将改动push到git上;
3.最后再pod trunk push就可以了。


更新结束,然后就可以更新你本地工程的`Podfile`文件中的版本号,再执行`pod update xxx`,就可以将刚刚上传的版本拉下来,检查一下更新的版本是否有问题。

***

##遇到的问题及解决方法

- 问题1 .

NOTE | [OSX] xcodebuild: UIImageKit/UIImageKit/UIImage+Generate.h:9:9: fatal error: 'UIKit/UIKit.h' file not found

> 解决:.podspec文件没有添加下面两个字段,加上就好了

s.platform = :ios
s.framework = "UIKit"


- 问题2.

- ERROR | file patterns: The `source_files` pattern did not match any file.
> 解决:.podspec文件中的`source_files`格式填写的不对,找不到资源文件

source_files:资源文件,当前路径就是库路径,后面再拼接库文件所在的文件夹,
” 表示匹配所有文件
.{h,m}” 表示匹配所有以.h和.m结尾的文件
“**” 表示匹配所有子目录


- 问题3.

    - WARN  | description: The description is equal to the summary.
> 解决:这是一个警告,原因是.podspec中的description字段和summary字段内容填写的一样,改成不一样的就没有了。

- 问题4.
在执行
`pod trunk push UIImageKit.podspec`
命令后一只卡在
`Updating spec repo master ` 这一步,
需要等待一段时间后,会出现

[!] Unable to accept duplicate entry for: UIImageKit (1.0.0)


库其实没有传上去,搜索不到。

> 解决:
使用命令:

pod setup

再进行一次`pod trunk push`,如果还不行的话,可以使用命令:

pod repo update --verbose


- 问题5.

    [!] Unable to find a pod with name, author, summary, or descriptionmatching `xxx`
> 解决:搜索不到你的库,使用下面的命令,一处搜索目录的缓存文件,然后再search

rm ~/Library/Caches/CocoaPods/search_index.json



[UIImageKit](https://github.com/Kangqj/UIImageKit/tree/master/UIImageKit)

相关文章

网友评论

    本文标题:CocoaPods上传流程及问题解决

    本文链接:https://www.haomeiwen.com/subject/jyzykxtx.html