CocoaPods创建私有Pod库方法

好记性不如烂笔头,今天记录一下CocoaPods创建私有Pod库方法,以码云作为第三方私有仓库为例。
1、创建一个git仓库用来做内部私有库的Spec Repo,命名为Pods(自己喜欢怎么命名都可以),如下图:


image.png

注意:一定要勾选为私有

2、打开终端执行以下代码(因为现在创建的是一个空仓库,执行以下命令是为了创建README.md):

mkdir Pods
cd Pods
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://gitee.com/xxxx/Pods.git
git push -u origin master

注意:其中https://gitee.com/xxxx/Pods.git就是这个仓库的地址

当执行完毕以上的命令以后,回到仓库页面刷新,你会看到以下页面,说明成功创建README.md并上传到了git仓库了。


image.png

到这一步,存储内部私有库的Spec Repo的git仓库就算建立完毕了。

下面开始创建真正的私有库。
1、首先在第三方git的仓库,命名为SLKit,步骤跟上面的1和2一样的。
执行完以上的步骤,然后把项目拉下来本地,然后在本地进行开发。
我在工程目录下创建了SLKit文件夹,在这个文件夹下创建了NSString+HDDmd5.h和NSString+HDDmd5.m文件,如下图:


image.png

编辑完成以后,在终端执行以下命令把代码提交到远程仓库:

cd 到目标文件
git add -A
git commit -m "增加NSString+HDDmd5.h和NSString+HDDmd5.m文件"
git push origin master

2、可以通过如下代码创建podspec文件

pod spec create SLKit

3、用Xcode 打开SLKit.podspec文件进行编辑


image.png

编辑SLKit.podspec文件

#
#  Be sure to run `pod spec lint SLKit.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         = "SLKit"
#项目版本号
spec.version      = "1.0.0"
#项目的描述
spec.summary      = "SLKit私有库."

# 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
SLKit私有库
               DESC

#项目的主页
spec.homepage     = "https://gitee.com/snailLi"
# 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             = { "xxxxx" => "[email protected]" }
# Or just: spec.author    = "xxxxx"
# spec.authors            = { "xxxxxx" => "[email protected]" }
# spec.social_media_url   = "https://xxxxxx"

# ――― 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, "10.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.
#

#项目git仓库的地址
spec.source       = { :git => "https://gitee.com/snailLi/SLKit.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.
#

#pod时需要集成的文件  一定要加上swift  不然报错
spec.source_files  = "SLKit/SLKit/*.{h,m,swift}"
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.

#是否要求arc(有部分非arc文件情况未考证)
spec.requires_arc = true

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

end

.podspec文件具体简介可以参考这边文章 https://www.jianshu.com/p/5ca47f960379

4、本地验证.podspec文件,打开终端执行以下命令:

pod lib lint SLKit.podspec --allow-warnings

如果看到 SLKit passed validation. 说明本地杨峥通过了

5、提交.podspec文件到远程git仓库并打标签,执行以下命令:

 git add -A && git commit -m "version 1.0.0"
 git tag '1.0.0'    //和上面.podspec一致
 git push --tags
 git push origin master

6、提交完毕以后,执行以下命令进行远程验证.podspec文件

pod spec lint SLKit.podspec --allow-warnings

如果出现了SLKit.podspec passed validation. 说明远程验证成功了

7、执行以下命令将Pods添加到本地repo

pod repo add Pods https://gitee.com/snailLi/Pods.git

添加成功后可以在/.cocoapods/repos/目录下可以看到官方的specs:master和刚刚加入的specs:Pods

8、执行以下命令,将SLKit加入私有Sepc repo中

pod repo push Pods SLKit.podspec --allow-warnings

出现如下图说明添加成功了


image.png

新建工程验证是否可以正确pod下来

Podfile文件填写如下:


image.png

成功pod下来SLKit


image.png

至此,简单的CocoaPods创建私有Pod库就制作完毕了

你可能感兴趣的:(CocoaPods创建私有Pod库方法)