废话没有,直接开干,因Github国内连接性不好,所以以下内容全部基于Gitee。
这个库的功能和cocoapods的Specs库功能一样,单纯的存放私有化pod库的podSpec文件,也就是我们代码库的索引文件。
库的名字随意但是最好带个Specs的后缀,能一眼看出来是干啥的。
创建成功之后
此时这个Specs库是空的。
这个时候最好点击**【初始化readme文件】**,省的后面蜜汁问题。
打开终端 输入
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
打开终端
进入到自己想保存项目的目录下
假如我要新建一个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
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 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了。
我们再次 进入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 所以等于账户一直有效 可以提交代码
做到这里仓库里面就已经有我们的提交记录了
根据上一步的结果,我们得到一个git网址:https://gitee.com/ilongge/test-manager.git
打开Xcode的TestManager下的Podspec Metadata目录,我们可以看到TestManager.podspec文件
我们需要修改一下里面的地址配置:
s.homepage = 'https://github.com/ilongge/TestManager'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'ilongge' => '[email protected]' }
s.source = { :git => 'https://github.com/ilongge/TestManager.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/'
修改成
# 项目主页
s.homepage = 'https://gitee.com/ilongge/test-manager'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'ilongge' => '[email protected]' }
# 项目的代码地址,实际项目中引用的源码地址
s.source = { :git => 'https://gitee.com/ilongge/test-manager.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/'
另外新增,移除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名字一定要和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.
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
# 动态库
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