前言
- 制作屬于自己的組件庫并上傳至CocoaPods
一、先將代碼傳到github上
1.創(chuàng)建本地倉庫
git init
2.添加名稱為origin的遠程連接git remote add origin 'Github項目地址'
3.將本地代碼加入到本地倉庫git add .
4.提交修改到本地倉庫git commit -m '修改記錄'
5.推送master分支的代碼到名稱為orgigin的遠程倉庫git push origin master
二那婉、給你git打上tag
打tag的目的就相當于給你的開源框架制定版本號,每個版本一個tag
1.cd倉庫目錄
2.查看本地taggit tag
3.添加本地tag 1.0.0git tag -a 1.0.0 -m 'release 1.0.0'
image
4.將tag傳到遠程git push origin --tags
tag的其他操作
1.刪除本地tag
git tag -d 1.0.0
2.刪除遠程taggit push origin -d tag 1.0.0
三忽妒、注冊Trunk
1.注冊Trunk
pod trunk register 郵箱 '用戶名' --description='描述'
image
成功的話就會受到一份郵件,點擊郵件中的鏈接后驗證一下:
2.打開郵箱點擊地址:https://trunk.cocoapods.org/sessions/verify/965b5e96
點擊紅色terminal跳轉(zhuǎn)回到終端
image
3.注冊
pod trunk me
成功會看到如下類似字段:
image
4.如果你的pod是由多人維護的兼贸,你也可以添加其他維護者
pod trunk add-owner 名稱 郵箱
四段直、獲取MIT文件
1.網(wǎng)頁鏈接 https://choosealicense.com/
image
復制,修改相應(yīng)的數(shù)據(jù)
image
2.將生成的LICENSE文件同步至Github
五寝受、創(chuàng)建自己項目的Podspec描述文件
1.創(chuàng)建podspec文件
pod spec create KJEmitterView
2.podspec文件代碼
Pod::Spec.new do |s|
s.name = "KJEmitterView"
s.version = "1.0.0"
s.summary = "Some iOS Emitter"
s.homepage = "https://github.com/yangKJ/KJEmitterView"
s.license = "MIT"
s.license = { :type => "MIT", :file => "LICENSE" }
s.license = "Copyright (c) 2018 yangkejun"
s.author = { "77" => "ykj310@126.com" }
s.platform = :iOS
s.source = { :git => "https://github.com/yangKJ/KJEmitterView.git", :tag => "#{s.version}" }
s.framework = "UIKit"
# s.dependency "JSONKit", "~> 1.4"
s.requires_arc = true
s.subspec 'Classes' do |ss|
ss.source_files = "KJEmitterView/Classes/**/*.{h,m}" # 添加文件
ss.public_header_files = 'KJEmitterView/Classes/*.h',"KJEmitterView/Classes/**/*.h" # 添加頭文件
ss.resources = "KJEmitterView/Classes/**/*.{bundle}" # 添加數(shù)據(jù)資料
end
end
3.驗證你本地的podspec文件
pod spec lint KJEmitterView.podspec
4.忽略警告pod spec lint KJEmitterView.podspec --allow-warnings
驗證成功坷牛,
image
六、傳到CocoaPods上
1.首先驗證你本地的podspec文件很澄,之后會上傳spec文件到trunk
2.將podspec文件傳到trunk上pod trunk push KJEmitterView.podspec
成功如下:
image
3.一直處于Updating spec repo master 狀態(tài)
可以選擇更新下pod repo update --verbose
4.檢查是否上傳成功:pod search KJEmitterView
七京闰、Bug總結(jié)
1颜及、[!] There was an error registering with trunk: getaddrinfo: nodename nor servname provided, or not known
- 解決方案:開啟了ShadowSocks,把ShadowSocks關(guān)閉再重試就好了蹂楣,根本原因是DNS不對
- 附上解決方案鏈接:https://link.jianshu.com/?t=https://github.com/CocoaPods/CocoaPods/issues/2174
2俏站、- WARN | [iOS] license: Unable to find a license file
- 原因:沒有找到License文件,根據(jù)規(guī)則也可以直接把文本寫在podspec文件里
- 解決方案:podspec文件里面添加
- s.license = "Copyright (c) 2018 yangkejun"
3痊土、- WARN | source: The version should be included in the Git tag.
- 原因:podspec里的version要跟git上的tag相匹配
- 解決方案:
- 查看當前tag: git tag
- 推到遠端: git push --tags
4肄扎、[!] Unable to accept duplicate entry for: KJEmitterDemo (1.0.0)
- 原因:重復
- 解決方案:
- 4.1.重新給git庫添加tag git tag -a 1.0.1 -m'release 1.0.1'
- 4.2.上傳到遠端 git push origin --tags
- 4.3.重新修改podspec文件 s.version = "1.0.1"
- 4.4.再次校驗 pod spec lint KJEmitterDemo.podspec --allow-warnings
- 4.5.最后上傳到trunk pod trunk push KJEmitterDemo.podspec
5、[!] Unable to find a pod with name, author, summary, or description matching KJEmitterDemo
- 原因:審核過程是要兩三天
- 解決方案:
- 執(zhí)行
pod setup
命令進行本地依賴庫更新赁酝,然后再搜索 - 如果還是不行刪除~/Library/Caches/CocoaPods目錄下的search_index.json文件
- 執(zhí)行
rm ~/Library/Caches/CocoaPods/search_index.json
- 然后再執(zhí)行搜索
pod search KJEmitterDemo
-
成功如下:
image
6犯祠、校驗不通過
可能原因:github上面的tag文件格式已經(jīng)確定,下圖位置下載下來看一下,是否和本地的文件格式保持一致酌呆。如果不一致按照下列方式解決bug衡载。
-
查看git上面的文件格式
image -
Github上面下載下來的文件格式:
image -
本地文件格式:
image -
需要校驗的格式:
image
- 解決方案:很明顯不一樣
- 刪除本地tag:
git tag -d 1.0.0
- 刪除遠端tag:
git push origin -d tag 1.0.0
- 重新添加本地tag:
git tag -a 1.0.0 -m ‘release 1.0.0’
- 重新上傳到遠端:
git push origin --tags
- 再次校驗:
pod spec lint KJEmitterView.podspec
7、[!] There was an error pushing a new version to trunk: execution expired
- 原因:推送過期
- 解決方案:重新將podspec文件傳到trunk上
pod trunk push KJEmitterView.podspec
8隙袁、- ERROR | [iOS] public_header_files: The pattern includes header files that are not listed in source_files
- 原因:文件夾層次結(jié)構(gòu)過淺痰娱,導致無法找到對應(yīng)的文件
- 解決方案:默認的頭文件目錄設(shè)置為:
- s.public_header_files = 'KJEmitterView/Classes/** / *.h'
- 但是如果Classes目錄中,你的代碼文件夾層次結(jié)構(gòu)超過兩級菩收,就會出現(xiàn)該錯誤梨睁。修改文件層級
9、搜索不到最新版本pod庫
- 原因:沒有更新pod庫
- 解決方案:更新pod庫
- pod update 要更新庫的名字
- 查看Podfile文件中的依賴庫的最新版本:pod outdated
10娜饵、代碼中有__weak typeof(self) weakSelf = self;
- 原因:有__weak就一直驗證不通過
- 解決方案:s.frameworks當中加入可以用__weak的庫
11坡贺、代碼中有dispatch_source_t
庫相關(guān)
- 原因:有
dispatch_source_t
相關(guān)的庫函數(shù),也一直驗證不通過 - 解決方案:s.frameworks當中加入可以用
dispatch_source_t
的庫
12箱舞、- ERROR | [KJEmitterView/Classes] xcodebuild: KJEmitterView/KJEmitterView/Classes/AlertView/KJAlertView.m:163:116: error: property 'height' not found on object of type 'UILabel *'
- 原因:未引入頭文件UIView+KJFrame在KJAlertView當中
- 解決方案:引入頭文件
13拴念、- NOTE | [iOS] [KJEmitterView/Classes] xcodebuild: KJEmitterView/KJEmitterView/Classes/AlertView/KJAlertView.m:10:9: fatal error: 'UIView+KJFrame.h' file not found
- 原因:不在同一個文件夾下面
- 解決方案:修改不引入該頭文件的錯誤,或者將需要引入的頭文件和KJAlertView放在同一個文件夾之下褐缠。
14、ERROR | name: The name of the spec should match the name of the file.
- 原因:文件名字不一樣
- 解決方案:xxx.podspec 文件名必須和文件里面的 s.name 文件名 "xxx" 保持一致
15风瘦、ERROR | [iOS] unknown: Encountered an unknown error (Could not find a ios
simulator (valid values: com.apple.coresimulator.simruntime.ios-12-2, com.apple.coresimulator.simruntime.tvos-12-2, com.apple.coresimulator.simruntime.watchos-5-2). Ensure that Xcode -> Window -> Devices has at least one ios
simulator listed or otherwise add one.) during validation.
- 解決方案:升級CocoaPods队魏,終端執(zhí)行 sudo gem install cocoapods 代碼即可