最近更新 2023.3.31
私有Cocoapods仓库&遇到的问题
pod索引库
私有pod仓库
pod组件化
pod遇到的问题
Git代码搬迁
在新Git服务器创建需要迁移的同名空项目(不同名也可以)
Git clone 旧Git代码到本地 (或者本地有Git origin的代码,用Git remote -v 查看)
Git push --mirror 新的空项目地址
完成后Git clone 新Git上的代码到本地game over
Pod 私有库(子组件)
1. 创建工程以YBBluetoothKit
为例
pod lib create YBBluetoothKit
#然后回答几个问题
#选择平台
What platform do you want to use?? [ iOS / macOS ]
> ios
#选择语言
What language do you want to use?? [ Swift / ObjC ]
> swift
#是否需要Demo
Would you like to include a demo application with your library? [ Yes / No ]
> yes
#是否使用测试工具
Which testing frameworks will you use? [ Quick / None ]
> none
#是否进行视图测试
Would you like to do view based testing? [ Yes / No ]
> no
2. 设置podspec 文件
注意必须修改的内容
Pod::Spec.new do |s|
# 库名称,默认和工程名相同,建议不改
s.name = 'YTPrivateBaseKit'
# 库的版本,每次升级版本后必须要在这里修改版本号
s.version = '0.1.0'
# 该库的简介,更改成适合的简介,使用默认简介会出现简介没有意义的错误
s.summary = '这是一个蓝牙库.'
# 详细描述,一般不用改,有readme呢
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
# 库的主页,需要更改为正确的主页
s.homepage = 'http://101.132.74.65/fengming/YBBluetoothKit'
# 许可,私有库可以不改
s.license = { :type => 'MIT', :file => 'LICENSE' }
# 作者,可以不改
s.author = { 'fengming' => '1028708571@qq.com' }
# 库的克隆地址,这个地址必须改成正确的克隆地址,可以是 https 或 ssh
s.source = { :git => 'http://101.132.74.65/fengming/YBBluetoothKit.git', :tag => s.version.to_s }
# 该库最低支持版本,可以修改为对应版本
s.ios.deployment_target = '10.0'
# 该库上传文件的路径,默认是 Classes 文件夹下的所有文件夹及文件,默认不需要改
s.source_files = 'YBBluetoothKit/Classes/**/*'
#--------------------------------------------------
# 以下是默认没有但可以自行添加的基础配置
# 设置指定版本号或非指定版本号的依赖库,
#s.dependency 'SnapKit'
# 指定 Swift 语言版本,Swift 项目需要设置这个
# s.swift_version = '4.2'
end
5.本地校验pod lib lint
cd 到YBBluetoothKit => YBBluetoothKit.podspec 所在目录
pod lib lint --allow-warnings
出现YBBluetoothKit passed validation.
表示成功
6. 创建远程库
在Git远端创建项目
7. 关联远程库
git remote add origin "http://101.132.74.65/fengming/YBBluetoothKit"
8.提交代码并为项目打上tag
git add .
git commit -m "project init"
git tag -m "first dev v0.1.0" 0.1.0
git push
git push --tags
9 .联网校验pod spec lint
Pod 索引库(主仓库)
如果已经创建过,就不需要再创建了
1. 在Git远端创建主工作项目 以ManagerSpecRepo
为例
创建一个空的远端项目即可
2. 将索引库添加(关联)到CocoaPods的目录下
pod repo add ManagerSpecRepo http://101.132.74.65/fengming/ManagerSpecRepo
3.将子组件YBBluetoothKit.podspec
添加并推送到ManagerSpecRepo
主仓库
pod repo push ManagerSpecRepo YBBluetoothKit.podspec
查看本地索引库
pod repo list
删除本地索引库
pod repo remove name
Pod私有库更新流程
将修改过的子组件文件的.podspec文件,修改version即可
打tag,并将tag上传 (git push origin [tagname] / git push origin --tags)
pod lib lint --allow-warnings
pod repo push 主仓库 子组件.podspec --verbose --allow-warnings
如果有.a都静态库使用
--use-libraries
pod repo push ManagerSpecRepo YBBluetoothKit.podspec --verbose --use-libraries --allow-warnings
- 如果里面已经依赖了其他私有库 需要指定 sources 地址(以逗号隔开)
pod repo push ManagerSpecRepo YBBluetoothKit.podspec --verbose --use-libraries --allow-warnings --sources="http://101.132.74.65/fengming/ManagerSpecRepo,https://github.com/CocoaPods/Specs.git"
Pod私有库异常整理
1. pod lib lint (检查本地pod)
[!] DemoPodSpecs did not pass validation, due to 2 warnings (but you can use --allow-warnings to ignore them).
You can use the --no-clean option to inspect any issue.
解决办法:用 pod lib lint --allow-warnings 命令
2. pod spec lint (检查远程pod)
Encountered an unknown error (Simulator is not available.) during validation
解决办法:升级cocoapods sudo gem install -n /usr/local/bin cocoapods --pre
3. pod spec lint (检查远程pod)
[iOS] unknown: Encountered an unknown error (Must be in the root of the repo (/Users/*.cocoapods/repos/master), instead in ....
解决办法:可能是因为更新完Xcode以后Xcode路径更改了,Xcodebuild找不到路径。 执行命令 sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
4. pod repo push DemoPodSpecs DemoPodSpecs.podspec
The DemoPodSpecs.podspec
specification does not validate.
解决办法: pod repo push DemoPodSpecs DemoPodSpecs.podspec --verbose --use-libraries --allow-warnings
5. pod repo push DemoPodSpecs DemoPodSpecs.podspec --verbose --use-libraries --allow-warnings
/usr/bin/git -C /Users/.cocoapods/repos/DemoPodSpecs -C
/Users/.cocoapods/repos/DemoPodSpecs push origin master
fatal: repository '' not found
解决办法:到 /Users/.cocoapods/目录下查看私有pod库是否存在
6. pod lib lint
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run: `echo "2.3" > .swift-version`.
解决办法:运行 echo 4.2 > .swift-version
7. Pod install
7.1
[!] CocoaPods could not find compatible versions for pod "YBCoreKit":
In snapshot (Podfile.lock):
YBCoreKit (= 1.2.1)
In Podfile:
YBSDKPayKit (from ../) was resolved to 1.8.1, which depends on
YBCoreKit
It seems like you've changed the constraints of dependency YBCoreKit inside your development pod YBSDKPayKit.
You should run pod update YBCoreKit to apply changes you've made.
解决办法:
- 注释掉source,和所以pod 库,以及pod 'demo', :path => '../',然后
pod install
- 重新打开注释掉的内容,然后
pod install
7.2 Unable to find a specification for ""
解决办法:
别着急pod update
一下就好了