Cocoapod搭建私有库详细教程

Cocoapod搭建私有库详细教程

一、准备工作

  • 创建两个私有远程仓库 WYSpecWYLib
    -- WYSpec仓库用来存储spec
    -- WYLib用来存储项目工程文件

二、创建pod私有库的项目工程

  • cd到合适目录下用命令行创建工程
    执行pod lib create WYLib
    按提示输入需要的内容
image

完成后项目会自动打开

  • 然后进到到WYLib文件夹中找到Classes中的"ReplaceMe.m"文件删除,然后将自己所需要的文件放到这里目录下,如图

    image
  • cdExample路径下, 执行pod install 更新Example项目中的pod

    image
image
  • 打开Example 中的.workspace文件 打开工程
    找到.podspec

    image
  • 修改podspec文件

    image
  • 修改完成后,cd 到WYLib目录下执行
    pod lib lint
    出现如下表示成功

    image

注意

如果项目用的swift4,报错内容如下

- WARN | [iOS] swift: The validator used Swift 3.2 by default because no Swift version was specified. To specify a Swift version during validation, add the swift_version attribute in your podspec. Note that usage of the --swift-version parameter or a .swift-version file is now deprecated.

podspec中添加 s.swift_version = '4.0'

三、将本地项目文件上传到远程私有库中

$ git remote add origin http://git.weiyankeji.cn/APP/ios/WYLib.git
$ git add .
$ git commit -m "Initial commit"
$ git push -u origin master
//tag 值要和podspec中的version一致
$ git tag 0.1.0
//推送tag到服务器上
$ git push --tags

这时查看远程仓库应该有自己的项目文件了

四 校验spec

执行 pod spec lint
如图表示成功

image

如果报错 fatal: Remote branch 0.1.0 not found in upstream origin 说明本地项目没有上传到远程仓库

image

执行第三步就好

五、创建spec repo

  • 进入文件夹cd ~/.cocoapods/repos 可以查看本地spec repo

  • 指定管理 lib repospecs repourl
    pod repo add WYLib http://git.weiyankeji.cn/APP/ios/WYSpec.git
    注意 此处地址是spec仓库地址

  • 推送 podspecspecs repo
    pod repo push WYLib WYLib.podspec --sources=http://git.weiyankeji.cn/APP/ios/WYSpec.git

image

私有创建完成~

六 验证

创建一个新的项目 编写podfile文件

source 'http://git.weiyankeji.cn/APP/ios/WYSpec.git'

platform :ios, '9.0'

target 'TestLayer' do
  use_frameworks!
  pod 'WYLib'

end

cd项目中 执行pod install

image

完成

cocoapods 教程

</article>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容