參考資料:
iOS組件化開發(fā)(基礎(chǔ)篇)
iOS組件化(上篇)- 拆分基礎(chǔ)組件
Trunk賬號
1.認(rèn)證CocoaPods API的服務(wù)
2.用來管理公共倉庫中的自己的組件
在注冊trunk之前警绩,我們需要確認(rèn)當(dāng)前的CocoaPods版本是否足夠新闰非,trunk需要pod在0.33及以上版本
查看pod版本的指令: pod --version
更新pod的指令: sudo gem install cocoapods
$ pod trunk COMMAND 與CocoaPods API交互(例如發(fā)布新規(guī)范)
+ add-owner 添加一個(gè)所有者到pod
+ delete 刪除pod的一個(gè)版本
+ deprecate 表示棄用pod
+ info 返回關(guān)于Pod的信息
+ me 顯示自己的信息
+ push 發(fā)布一個(gè)podspec
+ register 管理會話
+ remove-owner 從pod中移除所有者
可選參數(shù):
--allow-root 允許CocoaPods作為根運(yùn)行
--silent 不顯示
--verbose 顯示更多調(diào)試信息
--no-ansi 顯示輸出沒有ANSI代碼
--help Show help banner of specified command
通過pod trunk register 你的郵箱地址 ‘用戶名’ 注冊trunk賬號
pod trunk register 948158677@qq.com 'kaige1123' --description='register date 20220411'
pod trunk me
- Name: [kaige1123]
- Email: 948158677@qq.com
- Since: August 2nd, 2020 06:52
- Pods:
- BuriedPointSDK
- Sessions:
- April 11th, 03:04 - August 17th, 03:09. IP: 123.117.34.146 Description: register date 20220411
索引文件庫
1.存放索引文件的倉庫
2.儲存在CocoaPods服務(wù)器上,我們下載或更新Pod的時(shí)候會把這個(gè)倉庫拷貝一份到本地,本地存放路徑:~/.cocoapods/repos/
3.CocoaPods提供一個(gè)公共庫,儲存在本地的路徑為:~/.cocoapods/repos/master/
4.我們可以創(chuàng)建私有倉庫,儲存在本地的路徑為:~/.cocoapods/repos/自定義倉庫名/
$ pod repo [COMMAND] 管理spec-repositories
+ add 添加倉庫
+ add-cdn 添加一個(gè)支持CDN的倉庫
+ lint 驗(yàn)證倉庫協(xié)議
> list 倉庫列表
+ push 推送倉庫協(xié)議到倉庫
+ remove 移除倉庫
+ update 更新倉庫
可選參數(shù):
--allow-root 允許CocoaPods作為根運(yùn)行
--silent 不顯示
--verbose 顯示更多調(diào)試信息
--no-ansi 顯示輸出沒有ANSI代碼
--help Show help banner of specified command
//通過pod repo add <本地索引庫的名字> <遠(yuǎn)程索引庫的地址> ,創(chuàng)建本地索引庫并和遠(yuǎn)程索引庫做關(guān)聯(lián)
pod repo add LKVideoSpecs https://github.com/kaige1123/LKVideoSpecs.git
pod repo list
LKVideoSpecs
- Type: git (main)
- URL: https://github.com/kaige1123/LKVideoSpecs.git
- Path: /Users/xiaokai/.cocoapods/repos/LKVideoSpecs
master
- Type: git (master)
- URL: https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
- Path: /Users/xiaokai/.cocoapods/repos/master
trunk
- Type: CDN
- URL: https://cdn.cocoapods.org/
- Path: /Users/xiaokai/.cocoapods/repos/trunk
組件模板
1.CocoaPods提供用于快速創(chuàng)建組件的模板
2.里邊可以制作我們的代碼,可以做單元測試等,包含一個(gè)對應(yīng)的索引文件
3.組件化就是以這個(gè)模板為基礎(chǔ),制作自己的組件
cd /Users/xiaokai/Desktop/objects
pod lib create NAME:創(chuàng)建標(biāo)準(zhǔn)目錄結(jié)構(gòu)壁顶、模板文件。
pod lib create LKMacroCategoryModule
What platform do you want to use?? [ iOS / macOS ] 使用什么平臺
> ios
What language do you want to use?? [ Swift / ObjC ] 使用什么語言
> objc
Would you like to include a demo application with your library? [ Yes / No ] 是否生成一個(gè)用來做測試的模板
> yes
Which testing frameworks will you use? [ Specta / Kiwi / None ] 是否集成測試框架
> none
Would you like to do view based testing? [ Yes / No ] 是否做view測試
> yes
What is your class prefix? 類的前綴
> LK
Pod::Spec.new do |s|
#組件名稱
s.name = 'LKMacroCategoryModule'
#組件版本
s.version = '1'
#組件簡單描述
s.summary = 'A short description of LKMacroCategoryModule.'
# 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!
#組件詳細(xì)描述
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://github.com/kaige1123/LKMacroCategoryModule'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'kaige1123' => '948158677@qq.com' }
s.source = { :git => 'https://github.com/kaige1123/LKMacroCategoryModule.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
#組件支持的iOS系統(tǒng)版本
s.ios.deployment_target = '9.0'
#組件資源文件
s.source_files = 'LKMacroCategoryModule/Classes/**/*'
#組件資源,如:圖片,xib朋魔,json數(shù)據(jù)
# s.resource_bundles = {
# 'LKMacroCategoryModule' => ['LKMacroCategoryModule/Assets/*.png']
# }
#組件公共頭文件
# s.public_header_files = 'Pod/Classes/**/*.h'
#組件依賴的系統(tǒng)庫
# s.frameworks = 'UIKit', 'MapKit'
#組件依賴的第三方庫
# s.dependency 'AFNetworking', '~> 2.3'
end
cd /Users/xiaokai/Desktop/objects/LKMacroCategoryModule/Example
pod install
cd /Users/xiaokai/Desktop/objects/LKMacroCategoryModule
git add .
git commit -m"first commit"
git remote add origin https://github.com/kaige1123/LKMacroCategoryModule.git
git branch -M main
git push -u origin main
git tag 1
git push --tags
直接通過pod spec lint --verbose --allow-warnings 命令驗(yàn)證podspec索引文件(既驗(yàn)證本地同時(shí)驗(yàn)證遠(yuǎn)程的podspec)
pod spec lint --verbose --allow-warnings
驗(yàn)證通過后,pod repo push <本地索引庫> <索引文件名> --verbose --allow-warnings 提交索引文件到遠(yuǎn)程索引庫卿操。
pod repo push LKVideoSpecs LKMacroCategoryModule.podspec --verbose --allow-warnings
pod search LKMacroCategoryModule
-> LKMacroCategoryModule (1)
A short description of LKMacroCategoryModule.
pod 'LKMacroCategoryModule', '~> 1'
- Homepage: https://github.com/kaige1123/LKMacroCategoryModule
- Source: https://github.com/kaige1123/LKMacroCategoryModule.git
- Versions: 1 [LKVideoSpecs repo]
(END)
錯誤信息
/**
[!] Error installing LKMacroCategoryModule
-> LKCommonUIModule (1)
- WARN | summary: The summary is not meaningful.
- ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/kaige1123/LKMacroCategoryModule.git /var/folders/__/p13_j5b931s5c9k24btp8sbc0000gn/T/d20210418-38777-1k79mha --template= --single-branch --depth 1 --branch 1
Cloning into '/var/folders/__/p13_j5b931s5c9k24btp8sbc0000gn/T/d20210418-38777-1k79mha'...
fatal: unable to access 'https://github.com/kaige1123/LKMacroCategoryModule.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
[!] Error installing LKDLNAModule
-> LKDLNAModule (1)
- WARN | summary: The summary is not meaningful.
- ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/kaige1123/LKDLNAModule.git /var/folders/__/p13_j5b931s5c9k24btp8sbc0000gn/T/d20210418-38752-1dqc11x --template= --single-branch --depth 1 --branch 1
Cloning into '/var/folders/__/p13_j5b931s5c9k24btp8sbc0000gn/T/d20210418-38752-1dqc11x'...
fatal: unable to access 'https://github.com/kaige1123/LKDLNAModule.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
解決方法:清空xcode的緩存警检,重新編譯,然后push
*/
/**
pod search LKDLNAModule
[!] Unable to find a pod with name, author, summary, or description matching `LKDLNAModule`
解決方法:rm ~/Library/Caches/CocoaPods/search_index.json
pod search LKDLNAModule
*/
/**
-> LKCommonUIModule (2)
- WARN | summary: The summary is not meaningful.
- ERROR | [iOS] unknown: Encountered an unknown error (Unable to find a specification for `LKMacroCategoryModule` depended upon by `LKCommonUIModule`
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
校驗(yàn)podspec文件時(shí)會到遠(yuǎn)程podspec庫查找相關(guān)依賴害淤,默認(rèn)只會到官方specs庫校驗(yàn)扇雕,此時(shí)需要指定遠(yuǎn)程specs庫去校驗(yàn)。
podspec文件在寫依賴的時(shí)候也無法在對應(yīng)的庫后面添加源地址窥摄。但是我們可以在驗(yàn)證和提交的時(shí)候加上--sources參數(shù)洼裤。注意--sources后面也需要加上官方源,不然會報(bào)找不到公開的第三方庫溪王。
pod spec lint --verbose --use-libraries --allow-warnings --sources='私有庫地址,公有庫地址'
解決方法如下:
pod repo list
LKVideoSpecs
- Type: git (main)
- URL: https://github.com/kaige1123/LKVideoSpecs.git
- Path: /Users/xiaokai/.cocoapods/repos/LKVideoSpecs
master
- Type: git (master)
- URL: https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
- Path: /Users/xiaokai/.cocoapods/repos/master
trunk
- Type: CDN
- URL: https://cdn.cocoapods.org/
- Path: /Users/xiaokai/.cocoapods/repos/trunk
pod spec lint --verbose --use-libraries --allow-warnings --sources='https://github.com/kaige1123/LKVideoSpecs.git,https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
pod repo push LKVideoSpecs LKCommonUIModule.podspec --verbose --allow-warnings --sources='https://github.com/kaige1123/LKVideoSpecs.git,https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
*/
/**
- ERROR | xcodebuild: /Users/xiaokai/Library/Developer/Xcode/DerivedData/App-armubmuejrnbebfmusulgbaotvej/Build/Products/Release-iphonesimulator/LKHomeModule/LKHomeModule.framework/Headers/HomeBannerTableViewCell.h:10:9: error: include of non-modular header inside framework module 'LKHomeModule.HomeBannerTableViewCell': '/Users/xiaokai/Library/Developer/Xcode/DerivedData/App-armubmuejrnbebfmusulgbaotvej/Build/Products/Release-iphonesimulator/TYCyclePagerView/TYCyclePagerView.framework/Headers/TYCyclePagerView.h' [-Werror,-Wnon-modular-include-in-framework-module]
- ERROR | [iOS] xcodebuild: /Users/xiaokai/Library/Developer/Xcode/DerivedData/App-armubmuejrnbebfmusulgbaotvej/Build/Products/Release-iphonesimulator/LKHomeModule/LKHomeModule.framework/Headers/XKResponse.h:9:9: error: include of non-modular header inside framework module 'LKHomeModule.XKResponse': '/Users/xiaokai/Library/Developer/Xcode/DerivedData/App-armubmuejrnbebfmusulgbaotvej/Build/Products/Release-iphonesimulator/JSONModel/JSONModel.framework/Headers/JSONModel.h' [-Werror,-Wnon-modular-include-in-framework-module]
http://www.reibang.com/p/e73f8a5d5ec8
解決方式一:
把 target 下的 Build Settings 中的 Allow Non-modular includes in Framework Modules 設(shè)置成YES腮鞍。
或在Podfile文件中設(shè)置如下:
#允許非模塊化包含在框架模塊中
post_install do |installer|
installer.pods_project.build_configuration_list.build_configurations.each do
|configuration|
configuration.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
end
end
解決方式二:
方式二:
將#import "**.h" 第三方庫寫在 .m文件中,而不是放在.h文件中莹菱。
*/