创建Cocoapods的podspec

站在巨人的肩膀上,我们能眺望的更远,但我们依然需要一步步前行
本文借鉴以下两位老师的文章
https://blog.csdn.net/han_kang/article/details/107713121
https://www.jianshu.com/p/4fabfcd4c2d9

创建podspec

注意:名字最好起的复杂一些否则,你有可能到最后一步出错,导致重新开始....

1.0 github上创建自己的共有项目,这里需要注意点一点:就是右下角的license选成:MIT License


01.png

2.0创建自己的Xcode工程,注意这里我们选择的不是单纯的Application,而是Framework


02.png

3.0 先把github上的项目拉取下来,目的拉取LICENSE文件,随后上传提交到上面的repository,


03.png

04.png

4.0 创建podspec文件,打开终端,cd到项目目录,然后输入下面这段咒语,注意:pod spec create DemoFramework中的DemoFramework 要换成自己项目的名字、github.com后面换成自己的地址

pod spec create DemoFramework [email protected]:XXX/DemoFramework.git

5.0 编辑podspec文件,注意:

18行:记得换成自己的项目名字
20行:summary改一下
31行:换成自己的git地址
42行:spec.license = "MIT ()"
56行:spec.author相关信息我隐藏了自己的信息,其实不需要改动
68行附近:可以更改成自己想要的版本
83行:换成自己的git地址
94行:换成自己项目名称
95行:可以注释掉,用"#"注释
133行:打开注释

#
#  Be sure to run `pod spec lint DemoFramework.podspec' to ensure this is a
#  valid spec and to remove all comments including this before submitting the spec.
#
#  To learn more about Podspec attributes see https://guides.cocoapods.org/syntax/podspec.html
#  To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |spec|

  # ―――  Spec Metadata  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  These will help people to find your library, and whilst it
  #  can feel like a chore to fill in it's definitely to your advantage. The
  #  summary should be tweet-length, and the description more in depth.
  #

  spec.name         = "DemoFramework"
  spec.version      = "0.0.1"
  spec.summary      = "create a spec."

  # This description is used to generate tags and improve search results.
  #   * Think: What does it do? Why did you write it? What is the focus?
  #   * Try to keep it short, snappy and to the point.
  #   * Write the description between the DESC delimiters below.
  #   * Finally, don't worry about the indent, CocoaPods strips it!
  spec.description  = <<-DESC
                    create Spec
                   DESC

  spec.homepage     = "https://github.com/XXX/DemoFramework"
  # spec.screenshots  = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"


  # ―――  Spec License  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Licensing your code is important. See https://choosealicense.com for more info.
  #  CocoaPods will detect a license file if there is a named LICENSE*
  #  Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
  #

  spec.license      = "MIT ()"
  # spec.license      = { :type => "MIT", :file => "FILE_LICENSE" }


  # ――― Author Metadata  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the authors of the library, with email addresses. Email addresses
  #  of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
  #  accepts just a name if you'd rather not provide an email address.
  #
  #  Specify a social_media_url where others can refer to, for example a twitter
  #  profile URL.
  #

  spec.author             = { "D" => "[email protected]" }
  # Or just: spec.author    = "D"
  # spec.authors            = { "D" => "[email protected]" }
  # spec.social_media_url   = "https://twitter.com/D"

  # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If this Pod runs only on iOS or OS X, then specify the platform and
  #  the deployment target. You can optionally include the target after the platform.
  #

  # spec.platform     = :ios
  # spec.platform     = :ios, "11.0"

  #  When using multiple platforms
  # spec.ios.deployment_target = "5.0"
  # spec.osx.deployment_target = "10.7"
  # spec.watchos.deployment_target = "2.0"
  # spec.tvos.deployment_target = "9.0"


  # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the location from where the source should be retrieved.
  #  Supports git, hg, bzr, svn and HTTP.
  #

  spec.source       = { :git => "https://github.com/XXX/DemoFramework.git", :tag => "#{spec.version}" }


  # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  CocoaPods is smart about how it includes source code. For source files
  #  giving a folder will include any swift, h, m, mm, c & cpp files.
  #  For header files it will include any header in the folder.
  #  Not including the public_header_files will make all headers public.
  #

  spec.source_files  = "DemoFramework", "DemoFramework/**/*.{h,m}"
  #spec.exclude_files = "Classes/Exclude"

  # spec.public_header_files = "Classes/**/*.h"


  # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  A list of resources included with the Pod. These are copied into the
  #  target bundle with a build phase script. Anything else will be cleaned.
  #  You can preserve files from being cleaned, please don't preserve
  #  non-essential files like tests, examples and documentation.
  #

  # spec.resource  = "icon.png"
  # spec.resources = "Resources/*.png"

  # spec.preserve_paths = "FilesToSave", "MoreFilesToSave"


  # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Link your library with frameworks, or libraries. Libraries do not include
  #  the lib prefix of their name.
  #

  # spec.framework  = "SomeFramework"
  # spec.frameworks = "SomeFramework", "AnotherFramework"

  # spec.library   = "iconv"
  # spec.libraries = "iconv", "xml2"


  # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If your library depends on compiler flags you can set them in the xcconfig hash
  #  where they will only apply to your library. If you depend on other Podspecs
  #  you can include multiple dependencies to ensure it works.

 spec.requires_arc = true

  # spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
  # spec.dependency "JSONKit", "~> 1.4"

end

6.0 执行如下命令进行校验文件的正确性:

pod lib lint

这个时候会出现一些错误,这个时候去找是否是4.0 5.0的时候出现错误,如果没有错误的话,会出现下面的提示:就是一个warning,


05.png

有一些warning是不需要修改的,按提示输入咒语:

pod lib lint --allow-warnings
06.png

出现"DemoFramework passed validation."就代表着验证通过了。

7.0在github上传一个发布版本


07.png

08.png

然后在终端输入:pod spec lint,


09.png

将podspec发布CocoaPods

1.0 注册,使用以下命令在终端进行注册,注意项目名字不要错了,邮箱要能接收邮件,注册后需要点击邮箱内的链接进行验证

pod trunk register [email protected] "DemoFramework"
10.png

验证是否注册成功

pod trunk me
11.png

2.0 发布podspec

pod trunk push

然后报错:


12.png

行吧,把名字改复杂一些
见证一下成功的时刻吧


开心.png

然后,我们可以pod search一下,如果不出来的话
运行pod setup更新本地的spec,再搜索一下试试看。

删除~/Library/Caches/CocoaPods目录下的search_index.json文件

pod setup成功后会生成~/Library/Caches/CocoaPods/search_index.json文件。

终端输入rm ~/Library/Caches/CocoaPods/search_index.json
删除成功后再执行pod search

如果还是不行,别急,明天试试就有可能行了,这不是玄学,因为pods有延迟的

你可能感兴趣的:(创建Cocoapods的podspec)