好記性不如爛筆頭枚驻,今天記錄一下CocoaPods創(chuàng)建私有Pod庫(kù)方法,以碼云作為第三方私有倉(cāng)庫(kù)為例疤估。
1霎冯、創(chuàng)建一個(gè)git倉(cāng)庫(kù)用來(lái)做內(nèi)部私有庫(kù)的Spec Repo钞瀑,命名為Pods(自己喜歡怎么命名都可以),如下圖:
注意:一定要勾選為私有
2缠俺、打開(kāi)終端執(zhí)行以下代碼(因?yàn)楝F(xiàn)在創(chuàng)建的是一個(gè)空倉(cāng)庫(kù)贷岸,執(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就是這個(gè)倉(cāng)庫(kù)的地址
當(dāng)執(zhí)行完畢以上的命令以后偿警,回到倉(cāng)庫(kù)頁(yè)面刷新,你會(huì)看到以下頁(yè)面盒使,說(shuō)明成功創(chuàng)建README.md并上傳到了git倉(cāng)庫(kù)了。
到這一步少办,存儲(chǔ)內(nèi)部私有庫(kù)的Spec Repo的git倉(cāng)庫(kù)就算建立完畢了英妓。
下面開(kāi)始創(chuàng)建真正的私有庫(kù)。
1蔓纠、首先在第三方git的倉(cāng)庫(kù),命名為SLKit航闺,步驟跟上面的1和2一樣的猴誊。
執(zhí)行完以上的步驟,然后把項(xiàng)目拉下來(lái)本地乖杠,然后在本地進(jìn)行開(kāi)發(fā)澄成。
我在工程目錄下創(chuàng)建了SLKit文件夾,在這個(gè)文件夾下創(chuàng)建了NSString+HDDmd5.h和NSString+HDDmd5.m文件卫漫,如下圖:
編輯完成以后肾砂,在終端執(zhí)行以下命令把代碼提交到遠(yuǎn)程倉(cāng)庫(kù):
cd 到目標(biāo)文件
git add -A
git commit -m "增加NSString+HDDmd5.h和NSString+HDDmd5.m文件"
git push origin master
2、可以通過(guò)如下代碼創(chuàng)建podspec文件
pod spec create SLKit
3包吝、用Xcode 打開(kāi)SLKit.podspec文件進(jìn)行編輯
編輯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.
#
#項(xiàng)目名稱
spec.name = "SLKit"
#項(xiàng)目版本號(hào)
spec.version = "1.0.0"
#項(xiàng)目的描述
spec.summary = "SLKit私有庫(kù)."
# 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!
# 項(xiàng)目的描述
spec.description = <<-DESC
SLKit私有庫(kù)
DESC
#項(xiàng)目的主頁(yè)
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'.
#
# 驗(yàn)證許可證
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.
#
#項(xiàng)目git倉(cāng)庫(kù)的地址
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時(shí)需要集成的文件 一定要加上swift 不然報(bào)錯(cuò)
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文件具體簡(jiǎn)介可以參考這邊文章 http://www.reibang.com/p/5ca47f960379
4嚷狞、本地驗(yàn)證.podspec文件,打開(kāi)終端執(zhí)行以下命令:
pod lib lint SLKit.podspec --allow-warnings
如果看到 SLKit passed validation. 說(shuō)明本地楊崢通過(guò)了
5感耙、提交.podspec文件到遠(yuǎn)程git倉(cāng)庫(kù)并打標(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í)行以下命令進(jìn)行遠(yuǎn)程驗(yàn)證.podspec文件
pod spec lint SLKit.podspec --allow-warnings
如果出現(xiàn)了SLKit.podspec passed validation. 說(shuō)明遠(yuǎn)程驗(yàn)證成功了
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)如下圖說(shuō)明添加成功了
新建工程驗(yàn)證是否可以正確pod下來(lái)
Podfile文件填寫(xiě)如下:
成功pod下來(lái)SLKit
至此十饥,簡(jiǎn)單的CocoaPods創(chuàng)建私有Pod庫(kù)就制作完畢了