Cocoapods搭建私有库

分享
源代码 2024-9-14 17:20:16 111 0 来自 中国
随着公司项目越来越多,差别项目间会有很多雷同的功能代码。比如:网络获取、信息弹框、登岸等,将这些封装成模块module做成Cocoapods私有库大概Framework就很有须要了。这儿我想简单记录下Cocoapods私有库的搭建,如有错误 欢迎指正。
Framework 见我另一篇文章:ios Framework制作 (和踩过的坑)
搭建Cocoapods私有库

1、环境

Cocoapods环境,详细环境的设置过程其他文章有很多,就不说了。
2、搭建

私有库搭建组要有两部门:创建 repo 私有库的索引库  spec、创建私有库并发布到索引库。
<1>创建 repo 私有库的索引库  spec

在git上创建索引库  spec,我这儿用码云举例,方法和创建项目是一样的。

1.png 然后就有了索引库的地点:https://gitee.com/*******/test-module-specs.git
2.png 将索引库添加到本地堆栈
// pod repo add specs库名 specs库地点pod repo add TestModuleSpecs https://gitee.com/******/test-module-specs.git查察是否添加乐成
pod repo list//可以看到已经添加乐成TestModuleSpecs- Type: git (master)- URL:  https://gitee.com/*********/test-module-specs.git- Path: /Users/*******/.cocoapods/repos/TestModuleSpecs<2>创建私有库并发布到索引库

第一步:先在git上创建私有库,还是以码云举例。


然后就有了私有库地点:
https://gitee.com/*************/test-module-one.git
第二步:创建私有库模板
//创建私有库模板pod lib create TestModuleOne//下面是私有库的简单设置//选择平台What platform do you want to use?? [ iOS / macOS ] > ios//选择编程语言What language do you want to use?? [ Swift / ObjC ] > objc//选择是否创建测试demoWould 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 ] > no//类前缀What is your class prefix? > LU这就得到了库模板:

4.png
这就创建好了私有库模块了
编辑私有库索引 TestModuleOne.podspec
version             功能版本,发起和tag保持同等,版本从0.1.0开始。summary             功能概要,须要填写更新,否则lint检测无法通过。description         功能形貌,可以选择性删除,否则lint检测无法通过。homepage            资源首页,私有库对应的浏览器地点。resource            资源地点,git克隆地点。发起使用http/https,git范例有权限控制。source_file         类资源文件,默认Classes下的全部文件,放置私有库焦点文件。resources           Bundle资源文件(不保举使用),会归并至MainBundle中,访问便利,但会存在定名辩论问题。个别SDK必须放在MainBundle中才华使用,比如微博SDK!!!。resource_files      Bundle资源文件(保举使用),单独的Bundle文件,不与MainBundle归并,使用内部资源时和MainBundle路径有区别!!!。exclude_files       指定不被包罗的文件、目次vendored_libraries  内部包罗的.a静态库 比方'ModuleName/Classes/Lib/*.{a}'vendored_framework  内部包罗的.framework静态库 比方'ModuleName/Classes/Framework/***.framework'static_framework    指定pod加静态库标签 true/false指定支持的架构,假如因为i386等架构问题lint检测不通过,可以在检测时添加 --skip-import-validation参数s.xcconfig = {  'VALID_ARCHS' => 'armv7 arm64e armv7s arm64 x86_64',}假如支持单文件目次下的文件引用,可以设置subspecs.default_subspec = 'Core's.subspec 'Core' do |core|    core.dependency 'MBProgressHUD'    core.source_files  = "DYFoundationFramework/Classes/**/*.{h,m}"ends.subspec 'OldCommonTools' do |oct|    oct.dependency 'SAMKeychain'    oct.source_files  = "DY****Framework/Classes/Object-C/DY****Tools/**/*.{h,m}"end验证.podspec文件的格式是否精确
// 本地验证pod能否通过验证,假如失败使用下面下令: pod lib lint --verbose查察缘故原由pod lib lint// 大概使用pod lib lint --allow-warnings忽略告诫错误pod lib lint --allow-warnings// 当库中引用了其他三方库pod lib lint --allow-warnings --use-libraries将私有库代码提交到git
git remote add origin https://gitee.com/********/test-module-one.gitgit add .git commit -a -m "第一次提交 版本为0.1.0"git pull origin master --allow-unrelated-historiesgit push -f origin mastergit tag 0.1.0git push origin 0.1.0
podspec文件中的地点要和远程堆栈保持同等
git push -f origin master,本地欺压上传到远程,把远程的覆盖,这儿是第一次上传,全部就用本地代码覆盖掉远端代码了。
这儿就已经吧私有库代码提交到git上了
第三步:将私有库发布
//pod repo push 索引库名 私有库.podspecpod repo push TestModuleSpecs TestModuleOne.podspec --allow-warnings//查抄一下是否乐成pod search TestModuleOne-> TestModuleOne (0.1.0)   A short description of TestModuleOne.   pod 'TestModuleOne', '~> 0.1.0'   - Homepage: https://gitee.com/********/test-module-one   - Source:   https://gitee.com/******/test-module-one.git   - Versions: 0.1.0 [TestModuleSpecs repo]
这就算是搭建完成了
增补


  • XIB和storeboard文件须要放到Assets文件下,并在podspec文件中设置路径.
s.resource_bundles = {     'xxx' => ['xxx/Assets/*']   }

  • 库中用到MRC文件,须要在podspec中设置
non_arc_files = 'xxx/Classes/Bluetooth/protobuf-v1/xxx.{h,m}'  s.exclude_files = non_arc_files  s.subspec 'no-arc' do |sp|  sp.source_files = non_arc_files  sp.requires_arc = false  end

  • 在库中导入其他三方库头文件,须要用"#import <<#header#>>"方式,否则pod lib lint会失败。比方:
#import <Masonry/Masonry.h>参考文章:
https://www.jianshu.com/p/87145101636a
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-19 06:16, Processed in 0.172857 second(s), 35 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表