参考资料:
iOS组件化开发(基础篇)
iOS组件化(上篇)- 拆分基础组件
Trunk账号
1.认证CocoaPods API的服务
2.用来管理公共仓库中的自己的组件
在注册trunk之前,我们需要确认当前的CocoaPods版本是否足够新,trunk需要pod在0.33及以上版本
查看pod版本的指令: pod --version
更新pod的指令: sudo gem install cocoapods
$ pod trunk COMMAND 与CocoaPods API交互(例如发布新规范)
+ add-owner 添加一个所有者到pod
+ delete 删除pod的一个版本
+ deprecate 表示弃用pod
+ info 返回关于Pod的信息
+ me 显示自己的信息
+ push 发布一个podspec
+ register 管理会话
+ remove-owner 从pod中移除所有者
可选参数:
--allow-root 允许CocoaPods作为根运行
--silent 不显示
--verbose 显示更多调试信息
--no-ansi 显示输出没有ANSI代码
--help Show help banner of specified command
通过pod trunk register 你的邮箱地址 ‘用户名’ 注册trunk账号
pod trunk register [email protected] 'kaige1123' --description='register date 20220411'
pod trunk me
- Name: [kaige1123]
- Email: [email protected]
- 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服务器上,我们下载或更新Pod的时候会把这个仓库拷贝一份到本地,本地存放路径:~/.cocoapods/repos/
3.CocoaPods提供一个公共库,储存在本地的路径为:~/.cocoapods/repos/master/
4.我们可以创建私有仓库,储存在本地的路径为:~/.cocoapods/repos/自定义仓库名/
$ pod repo [COMMAND] 管理spec-repositories
+ add 添加仓库
+ add-cdn 添加一个支持CDN的仓库
+ lint 验证仓库协议
> list 仓库列表
+ push 推送仓库协议到仓库
+ remove 移除仓库
+ update 更新仓库
可选参数:
--allow-root 允许CocoaPods作为根运行
--silent 不显示
--verbose 显示更多调试信息
--no-ansi 显示输出没有ANSI代码
--help Show help banner of specified command
//通过pod repo add <本地索引库的名字> <远程索引库的地址> ,创建本地索引库并和远程索引库做关联
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提供用于快速创建组件的模板
2.里边可以制作我们的代码,可以做单元测试等,包含一个对应的索引文件
3.组件化就是以这个模板为基础,制作自己的组件
cd /Users/xiaokai/Desktop/objects
pod lib create NAME:创建标准目录结构、模板文件。
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 ] 是否生成一个用来做测试的模板
> 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!
#组件详细描述
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' => '[email protected]' }
s.source = { :git => 'https://github.com/kaige1123/LKMacroCategoryModule.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/'
#组件支持的iOS系统版本
s.ios.deployment_target = '9.0'
#组件资源文件
s.source_files = 'LKMacroCategoryModule/Classes/**/*'
#组件资源,如:图片,xib,json数据
# s.resource_bundles = {
# 'LKMacroCategoryModule' => ['LKMacroCategoryModule/Assets/*.png']
# }
#组件公共头文件
# s.public_header_files = 'Pod/Classes/**/*.h'
#组件依赖的系统库
# 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 命令验证podspec索引文件(既验证本地同时验证远程的podspec)
pod spec lint --verbose --allow-warnings
验证通过后,pod repo push <本地索引库> <索引文件名> --verbose --allow-warnings 提交索引文件到远程索引库。
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.
校验podspec文件时会到远程podspec库查找相关依赖,默认只会到官方specs库校验,此时需要指定远程specs库去校验。
podspec文件在写依赖的时候也无法在对应的库后面添加源地址。但是我们可以在验证和提交的时候加上--sources参数。注意--sources后面也需要加上官方源,不然会报找不到公开的第三方库。
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]
https://www.jianshu.com/p/e73f8a5d5ec8
解决方式一:
把 target 下的 Build Settings 中的 Allow Non-modular includes in Framework Modules 设置成YES。
或在Podfile文件中设置如下:
#允许非模块化包含在框架模块中
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文件中。
*/