irpas技术客

iOS--如何创建pod库_卟败灬筱龙_ios 创建pod

大大的周 4968

废话没有,直接开干,因Github国内连接性不好,所以以下内容全部基于Gitee。

第一步 创建一个Git库

这个库的功能和cocoapods的Specs库功能一样,单纯的存放私有化pod库的podSpec文件,也就是我们代码库的索引文件。

库的名字随意但是最好带个Specs的后缀,能一眼看出来是干啥的。

例如我新建一个ilonggePublicSpec

创建成功之后

此时这个Specs库是空的。

这个时候最好点击**【初始化readme文件】**,省的后面蜜汁问题。

第二步 添加Specs库到本地pod

打开终端 输入

pod repo add ilonggePublicSpecs https://gitee.com/ilongge/ilongge-public-specs.git

解释一下这个命令

pod repo add 是添加一个podspec库 ilonggePublicSpecs 给将要添加的库名一个本地的名字 https://gitee.com/ilongge/ilongge-public-specs.git 库的url 第三步 在本地创建自己的pod库

打开终端

进入到自己想保存项目的目录下

假如我要新建一个TestManager库

pod lib create TestManager

输入之后 下面会输出以下信息

Cloning `https://github.com/CocoaPods/pod-template.git` into `TestManager`. Configuring TestManager 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 ] > 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 ### 包含一个demo程序 当然得要 Which testing frameworks will you use? [ Specta / Kiwi / None ] > None ### 测试框架 无所谓 Would you like to do view based testing? [ Yes / No ] > yes ### 测试的 没管过 What is your class prefix? > XL ### 前缀是啥 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 <name> 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 <name> Running pod install on your new library. Analyzing dependencies Downloading dependencies Installing FBSnapshotTestCase (2.1.4) Installing TestManager (0.1.0) Generating Pods project Integrating client project [!] Please close any current Xcode sessions and use `TestManager.xcworkspace` for this project from now on. Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods 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 Xcode open 'TestManager/Example/TestManager.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`.

此时 Xcode会被自动打开,打开的是 TestManager/Example/TestManager.xcworkspace ,这时候我们先不要去动Xcode了。

第四步 创建远程git仓库

我们再次 进入Gitee站点,新建一个空仓库:TestManager,一定要是空的,不要初始化,直接点创建即可

根据上一步的结果,我们得到一个git网址:https://gitee.com/ilongge/test-manager.git

这个库是用来存放我们的pod库项目,下面我们会直接提交代码进来。

打开终端 进入TestManager目录执行:

git add . git commit -m "init project" git remote add origin https://gitee.com/ilongge/test-manager.git git push # 我本机已经设置过 gitee 的 ssh Key 所以等于账户一直有效 可以提交代码

做到这里仓库里面就已经有我们的提交记录了

第五步 配置podSpec文件

根据上一步的结果,我们得到一个git网址:https://gitee.com/ilongge/test-manager.git

打开Xcode的TestManager下的Podspec Metadata目录,我们可以看到TestManager.podspec文件

我们需要修改一下里面的地址配置:

s.homepage = 'https://github.com/ilongge/TestManager' # s.screenshots = '·/screenshots_1', '·/screenshots_2' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'ilongge' => '1015820857@qq.com' } s.source = { :git => 'https://github.com/ilongge/TestManager.git', :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

修改成

# 项目主页 s.homepage = 'https://gitee.com/ilongge/test-manager' # s.screenshots = '·/screenshots_1', '·/screenshots_2' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'ilongge' => '1015820857@qq.com' } # 项目的代码地址,实际项目中引用的源码地址 s.source = { :git => 'https://gitee.com/ilongge/test-manager.git', :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

另外新增,移除M1 CPU的模拟器arm64架构,因为真机也是Arm64,所以打包的时候会因为有两个而报错。

s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64', } s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64', }

指定向外部可引用的头文件

# 指定了Classes 目录下所有.h文件 s.public_header_files = 'TestManager/Classes/**/*.h'

剩下的配置需要依据各个项目的实际情况,具体可以去详细了解podspec文件的详细说明。

初步配置完成之后,进入Example文件夹下 执行 pod install,任何对于podspec文件的改动和资源的增删改,都需要执行。

第六步 添加项目实际代码

展开 Pods Target 下面的 Development Pods / TestManager

新建类 TestManager,保存于TestManager/Classes/目录下,执行 pod install

随便在TestManager类里面写点啥。

第七步 本地校验

打开终端

校验前 请在Example目录下执行 pod install

ilongge@ilonggedeMBP TestManager % cd Example ilongge@ilonggedeMBP Example % pod install Analyzing dependencies [!] The version of CocoaPods used to generate the lockfile (1.11.3) is higher than the version of the current executable (1.8.4). Incompatibility issues may arise. Downloading dependencies Generating Pods project Integrating client project Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.

返回上层 podspec文件所在目录 执行本地校验命令

ilongge@ilonggedeMBP Example % cd ../ ilongge@ilonggedeMBP TestManager % pod lib lint TestManager.podspec --allow-warnings -> TestManager ilongge@ilonggedeMBP TestManager % pod lib lint TestManager.podspec --allow-warnings -> TestManager (0.1.0) - WARN | summary: The summary is not meaningful. - WARN | url: The URL (https://gitee.com/ilongge/test-manager) is not reachable. - 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 dependency order - WARN | xcodebuild: /Users/ilongge/Library/Developer/Xcode/DerivedData/App-fshjujkcdagpixgavikcfrgmsalr/Build/Products/Release-iphonesimulator/TestManager/TestManager.framework/Headers/TestManager-umbrella.h:13:9: warning: double-quoted include "TestManager.h" in framework header, expected angle-bracketed instead [-Wquoted-include-in-framework-header] - 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') TestManager passed validation.

出现 TestManager passed validation. 表示校验通过

如果不加 --allow-warnings 稍等片刻之后 会出现下面命令

[!] TestManager did not pass validation, due to 3 warnings (but you can use `--allow-warnings` to ignore them). You can use the `--no-clean` option to inspect any issue. 第八步 给项目打上tag

经过上面的本地校验通过之后,我们就可以给项目打上tag了,请注意tag名字一定要和podspec文件里的 s.version 值一致。 是必须一致。

git tag 0.1.0 git push --tags 第九步 远程校验 pod spec lint TestManager.podspec --allow-warnings -> TestManager (0.1.0) - WARN | summary: The summary is not meaningful. - WARN | url: The URL (https://gitee.com/ilongge/test-manager) is not reachable. - 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 dependency order - WARN | xcodebuild: /Users/ilongge/Library/Developer/Xcode/DerivedData/App-glephpafxwwbmaabwrcvldbhurtq/Build/Products/Release-iphonesimulator/TestManager/TestManager.framework/Headers/TestManager-umbrella.h:13:9: warning: double-quoted include "TestManager.h" in framework header, expected angle-bracketed instead [-Wquoted-include-in-framework-header] - 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') Analyzed 1 podspec. TestManager.podspec passed validation. 第十步 提交podspec文件到spec仓库 pod repo push ilonggePublicSpecs TestManager.podspec --allow-warnings Validating spec -> TestManager (0.1.0) - WARN | summary: The summary is not meaningful. - WARN | url: The URL (https://gitee.com/ilongge/test-manager) is not reachable. - 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 dependency order - WARN | xcodebuild: /Users/ilongge/Library/Developer/Xcode/DerivedData/App-asjarzxbodcehhbteuarafmzewfk/Build/Products/Release-iphonesimulator/TestManager/TestManager.framework/Headers/TestManager-umbrella.h:13:9: warning: double-quoted include "TestManager.h" in framework header, expected angle-bracketed instead [-Wquoted-include-in-framework-header] - 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') Updating the `ilonggePublicSpecs' repo Adding the spec to the `ilonggePublicSpecs' repo - [No change] TestManager (0.1.0) Pushing the `ilonggePublicSpecs' repo 最后了 打包framework # 动态库 pod package TestManager.podspec --no-mangle --dynamic # 默认静态库 pod package TestManager.podspec --no-mangle Analyzing dependencies Fetching podspec for `TestManager` from `/Users/ilongge/Desktop/TestManager/TestManager.podspec` Downloading dependencies Installing TestManager (0.1.0) Generating Pods project Skipping User Project Integration Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed. Building static framework TestManager (0.1.0) with configuration Release


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #iOS #创建pod