CocoaPods創(chuàng)建私有Pod庫方法

好記性不如爛筆頭,今天記錄一下CocoaPods創(chuàng)建私有Pod庫方法,以碼云作為第三方私有倉庫為例。
1、創(chuàng)建一個git倉庫用來做內(nèi)部私有庫的Spec Repo,命名為Pods(自己喜歡怎么命名都可以),如下圖:


image.png

注意:一定要勾選為私有

2、打開終端執(zhí)行以下代碼(因為現(xiàn)在創(chuàng)建的是一個空倉庫,執(zhí)行以下命令是為了創(chuàng)建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就是這個倉庫的地址

當(dāng)執(zhí)行完畢以上的命令以后,回到倉庫頁面刷新,你會看到以下頁面,說明成功創(chuàng)建README.md并上傳到了git倉庫了。


image.png

到這一步,存儲內(nèi)部私有庫的Spec Repo的git倉庫就算建立完畢了。

下面開始創(chuàng)建真正的私有庫。
1、首先在第三方git的倉庫,命名為SLKit,步驟跟上面的1和2一樣的。
執(zhí)行完以上的步驟,然后把項目拉下來本地,然后在本地進行開發(fā)。
我在工程目錄下創(chuàng)建了SLKit文件夾,在這個文件夾下創(chuàng)建了NSString+HDDmd5.h和NSString+HDDmd5.m文件,如下圖:


image.png

編輯完成以后,在終端執(zhí)行以下命令把代碼提交到遠程倉庫:

cd 到目標(biāo)文件
git add -A
git commit -m "增加NSString+HDDmd5.h和NSString+HDDmd5.m文件"
git push origin master

2、可以通過如下代碼創(chuàng)建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" => "xxxxxxx@qq.com" }
# Or just: spec.author    = "xxxxx"
# spec.authors            = { "xxxxxx" => "xxxxxxx@qq.com" }
# 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.
#

# 適配的系統(tǒng)
spec.platform     = :iOS
#適配系統(tǒng)的最低版本
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文件具體簡介可以參考這邊文章 http://www.itdecent.cn/p/5ca47f960379

4、本地驗證.podspec文件,打開終端執(zhí)行以下命令:

pod lib lint SLKit.podspec --allow-warnings

如果看到 SLKit passed validation. 說明本地楊崢通過了

5、提交.podspec文件到遠程git倉庫并打標(biāo)簽,執(zhí)行以下命令:

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

6、提交完畢以后,執(zhí)行以下命令進行遠程驗證.podspec文件

pod spec lint SLKit.podspec --allow-warnings

如果出現(xiàn)了SLKit.podspec passed validation. 說明遠程驗證成功了

7、執(zhí)行以下命令將Pods添加到本地repo

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

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

8、執(zhí)行以下命令,將SLKit加入私有Sepc repo中

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

出現(xiàn)如下圖說明添加成功了


image.png

新建工程驗證是否可以正確pod下來

Podfile文件填寫如下:


image.png

成功pod下來SLKit


image.png

至此,簡單的CocoaPods創(chuàng)建私有Pod庫就制作完畢了

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容