发布自己的仓库到 Cocoapods

2020-09-09  本文已影响0人  _海阔天空
1、cd到工程目录下,创建.podspec文件

这里一定要在工程中创建 .podspec文件,并把库文件放在一个文件中。

// 这里的MYTagView就是你制作库的名字
pod spec create MYTagView
image
2、编辑.podspec

删除不必要东西 后如下

Pod::Spec.new do |spec|
  # 名称,pod search搜索的关键词,注意这里一定要和pod spec create MYTagView中的名称一样,否则报错
  spec.name         = "MYTagView"
  # 版本号
  spec.version      = "1.0.1"
  # 库的简介
  spec.summary      = "A banner for iOS."
  #项目主页
  spec.homepage     = "https://www.apple.com"

  # 许可证 
  spec.license      = { :type => "MIT", :file => "LICENSE" }

  #   作者信息 
  spec.author             = { "XXXX" => "XXXX@163.com" }
  # 社交地址
  # spec.social_media_url   = "https://www.XXXX"
  spec.platform     = :ios, "9.0"

  # 项目的地址(这个必须写正确)
  spec.source       = { :git => "https://github.com/lbj858585/MYTagViewDemo.git", :tag => spec.version }
 
  # 需要包含的源文件
  spec.source_files  = "MYTagView", "MYTagView/**/*.{h,m}"
  spec.exclude_files = "MYTagView/Exclude"
  spec.public_header_files = 'MYTagView/HeaderFiles.h'

  # 用到的系统库 引用多个用逗号隔开
   spec.framework  = "UIKit"
  # spec.frameworks = "SomeFramework", "AnotherFramework"

  # 是否需要ARC自动管理内存
  spec.requires_arc = true
  # 用到的第三方库
  spec.dependency "Masonry"

  # 如果需要多个依赖库,不是用逗号分隔
  # s.dependency  = 'Masonry'
  # s.dependency  = 'AFNetworking'
end

(PS: 主要注意资源文件的路径)

3、创建LICENSE(许可证/授权文件)
touch LICENSE
openLICENSE

将以下内容复制到文件里并保存 (PS:需要修改Copyright中的相关信息)

Copyright (c) 2020-2029 MYTagView Software Foundation (https://github.com/xxx/MYTagView/)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
4、验证编辑是否通过
pod lib lint MYTagView.podspec
验证成功通过 image
遇到问题,验证不通过,这时候按照错误提示解决错误即可 image.png
5、提交Git

将创建的.spec、LICENSE文件及功能代码提交Git 并 打tag

git add .
git commit -m "提交代码"
git push origin master  (推送到远程)
git tag "v1.0.1"
git tag   (查看版本号是否提交成功)
git push --tags

(PS: tag 版本要跟.podspec 里面的版本一致)

6、发布自己的pods到CocoaPods trunk
pod trunk push MYTagView.podspec
7、遇到问题
Cloning into '/var/folders/tc/lkhq3pjn0qj77p2pnz8fv46c0000gn/T/d20200909-73737-1o303ln'...
warning: Could not find remote branch 1.0.1 to clone.
fatal: Remote branch 1.0.1 not found in upstream origin
) during validation.

Analyzed 1 podspec.

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

看这里关键的一行

fatal: Remote branch 1.0.1 not found in upstream origin

说是因为从远程拉不到v1.0.1branch而引起的报错。
但是我明明已经更新到远程


image.png

后面各种百度,删除重新再打tag 还是不行。最后再打一个不带v的tag 居然可以了。(PS:怀疑是因为 .podspec 的 version 没有带v 导致的,有待实践)


image.png

至于打一个不带v的tag能不能 push 成功,这个有待实践

上一篇下一篇

猜你喜欢

热点阅读