作者:手机用户2502903481 | 来源:互联网 | 2023-09-25 09:11
前言
随着项目的业务增加以及马甲包进度的跟进,一些重复的独立业务以私有库的方式引入到项目中对于项目进度的开发就显得越发的迫切了,本文主要记录自己搭建私有库时的整个流程,以防后面再次搭建时忘记,方便自己查阅。
整个记录流程中私有库的存储是在码云中,也可以在公司自己的git仓库中,自己选择即可。
私有库的搭建涉及到创建索引库和私有库,这里解释下两者:
索引库:存放spec文件的仓库,找到代码位置的索引。
私有库:存放代码的仓库。
两者像指针和对象的关系,指针中存放对象的地址,可以通过指针找到对象。两个仓库创建后,通过命令行将两者关联起来,这样整个私有库的搭建过程就完成了。
1、创建索引库
创建的这个空的仓库,是用来存放我们自己所有的私有库的 spec 文件, 就如同官方的 https://github.com/CocoaPods/Specs 是用来存放所有官方的 specs 文件一样。
2、将索引库添加到本地cocoapods仓库
通过命令行添加自己的索引库到本地仓库
pod repo add wyonSpec https://gitee.com/wyon_wang/wyon-spec.git
添加完毕后查看本地仓库
以上就创建完成了一个自己的索引仓库,该仓库只存放各组件的索引文件,不存放代码!!!
3、创建工程模板
wyondeMacBook-Pro:~ wyon$ cd /Users/wyon/Desktop/TestProject
wyondeMacBook-Pro:TestProject wyon$ pod lib create YGTool
Cloning `https://github.com/CocoaPods/pod-template.git` into `YGTool`.
Configuring YGTool template.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.------------------------------To get you started we need to ask a few questions, this should only take a minute.If this is your first time we recommend running through with the guide: - https://guides.cocoapods.org/making/using-pod-lib-create.html( hold cmd and double click links to open in a browser. )What platform do you want to use?? [ iOS / macOS ]> iOSWhat language do you want to use?? [ Swift / ObjC ]> ObjCWould you like to include a demo application with your library? [ Yes / No ]> YESWhich testing frameworks will you use? [ Specta / Kiwi / None ]> NoneWould you like to do view based testing? [ Yes / No ]> NoWhat is your class prefix?> YG_
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m Running pod install on your new library.Analyzing dependencies
Downloading dependencies
Installing YGTool (0.1.0)
Generating Pods project
Integrating client project[!] Please close any current Xcode sessions and use `YGTool.xcworkspace` for this project from now on.
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.[!] Your project does not explicitly specify the CocoaPods master specs repo. Since CDN is now used as the default, you may safely remove it from your repos directory via `pod repo remove master`. To suppress this warning please add `warn_for_unused_master_specs_repo => false` to your Podfile.Ace! you're ready to go!We will start you off by opening your project in Xcodeopen 'YGTool/Example/YGTool.xcworkspace'To learn more about the template see `https://github.com/CocoaPods/pod-template.git`.
To learn more about creating a new pod, see `https://guides.cocoapods.org/making/making-a-cocoapod`.
wyondeMacBook-Pro:TestProject wyon$
通过该命令行自动创建一个模板工程,其中包含我们所需的索引文件,格式为.podspec。创建完后会自动打开该工程。
4、添加我们的组件到指定目录
这样我们本地私有库完成,接下来制作远端仓库
5、将本地库上传码云
这里是新创建一个项目,为我们真正存放代码的仓库。
我们可以根据码云中的提示上传模板文件
通过命令行上传组件文件
$ git add .
$ git commit -m '模板工程初始化'
$ git push -u origin master
之后我们修改下模板工程中的.podspec文件,如下图
6、验证spec文件
注意这里我们上次的代码一定要走的通,不然会校验失败。
wyondeMacBook-Pro:YGTool wyon$ cd /Users/wyon/Desktop/TestProject/YGTool
wyondeMacBook-Pro:YGTool wyon$ pod lib lint --private-> YGTool (1.0.0)- NOTE | xcodebuild: note: Using new build system- NOTE | xcodebuild: note: Using codesigning identity override: -- NOTE | xcodebuild: note: Build preparation complete- NOTE | [iOS] xcodebuild: note: Planning- NOTE | [iOS] xcodebuild: note: Building targets in parallel- NOTE | [iOS] xcodebuild: warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')YGTool passed validation.
验证成功后打分支,这里的分支一定要和.podspec文件中的版本号一致
$ git tag 1.0.0
$ git push --tags
7、私有库和索引库建立关联
pod repo push wyonSpec YGTool.podspec
这样就同步好了远程和本地索引库,到这里私有库搭建完毕,可以通过命令行搜索下自己的仓库查看一下
pod search YGTool