创建一个私有的 CocoaPods 库(pod)涉及几个步骤,包括设置私有的 Git 仓库、创建 Podspec 文件、发布到私有仓库等等。以下是详细步骤:
设置私有 Git 仓库
首先,在 GitHub、GitLab 或 Bitbucket 上创建一个新的私有仓库,假设仓库名为 MyPrivatePod。
创建本地 Pod 库
在本地创建一个新的 Pod 项目:
pod lib create MyPrivatePod CocoaPods 会询问你一些问题,比如平台、语言、示例项目等。根据你的需求选择合适的选项。
打开 MyPrivatePod.podspec 文件,并进行配置。例如:
Pod::Spec.new do |s| s.name = 'MyPrivatePod' s.version = '0.1.0' s.summary = 'A short description of MyPrivatePod.' s.description = <<-DESC A longer description of MyPrivatePod in markdown format. DESC s.homepage = 'https://github.com/username/MyPrivatePod' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'Your Name' => 'you@example.com' } s.source = { :git => 'https://github.com/username/MyPrivatePod.git', :tag => s.version.to_s } s.ios.deployment_target = '10.0' s.source_files = 'MyPrivatePod/Classes/**/*' end pod repo add MyPrivateRepo https://github.com/username/MyPrivatePodSpecs.git 这里 MyPrivateRepo 是你私有 Pod 仓库的名字,后面的 URL 是你在步骤 1 中创建的 Git 仓库的地址。
pod lib lint –verbose:显示详细的输出信息。
pod lib lint --verbose 指定源仓库
如果依赖一些私有库可以添加Specs的git路径
pod lib lint --sources='https://github.com/CocoaPods/Specs.git,https://github.com/username/privaterepo.git' –verbose 输出详情
–allow-warnings 允许警告,不然有警告就会终止
–use-libraries 允许使用静态库
–skip-import-validation 跳过验证
–no-clean 不清理打印
–swift-version=4.0 指定swift版本
这些命令对lib lint 或者 repo push都是作用的,有些莫名其妙问题每个命令都试一下,有时lib lint成功但是pod repo push 报错 ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code 这一种要看一下warning尽量解决,或者其它命令试一下
多条指令一起
pod spec lint --verbose --use-libraries --allow-warnings --sources='https://git.XXXXXX/MySpecs.git' –no-clean:在验证结束后不删除临时目录,这对调试很有帮助
pod lib lint --no-clean git add . git commit -m "Initial commit" git tag '0.1.0' git push --tags 然后在终端运行以下命令发布你的 Pod 到私有仓库:
xx.podspec 要上传的podspec 注意xx.podspec所在的路径,我这里使用的是相对路径,你也可以使用绝对路径比如:/Users/xxx/Documents/xx.podspec
pod repo push MyPrivateRepo MyPrivatePod.podspec source 'https://github.com/username/MyPrivatePodSpecs.git' source 'https://github.com/CocoaPods/Specs.git' target 'MyApp' do pod 'MyPrivatePod', '~> 0.1.0' end 然后运行 pod install:
pod install 有时候install不下来可以更新一下pod
pod repo update 这是使用pod管理,还有通过子工程管理方式,后面讲
上一篇:安卓自制拼图游戏软件
下一篇:为什么耳机接电话有杂音