CocoaPods私有库配置及遇到的问题

一、私有库配置过程

1、在 github 创建私有库仓库,如 TestRepos 。然后添加到本地。

pod repo add TestRepos https://git.oschina.net/skyfree666/TestRepos.git

完成后,私有库 TestRepos 添加到目录 ~/.cocoapods/repos 下,查看命令为:

pod repo list

2、创建工具库项目,如 TestLib

pod lib create TestLib

命令执行完,自动打开 TestLib 项目。

3、创建工具库的远程仓库 TestLib 。然后,修改配置文件 TestLib.podspec

git remote add origin https://git.oschina.net/skyfree666/TestLib.git
git add -A
git commit -m "0.1.0"
git pull origin master
git push origin master

git tag -a "0.1.0"
git push origin --tags

6、远程验证

pod spec lnit

7、将工具库 TestLib 添加到自己的私有库 TestRepos 中。

pod repo push TestRepos TestLib.podspec

然后,就可以在目录 ~/.cocoapods/repos/TestRepos 下看到工具库 TestLib

8、具体使用
Podfile 中添加自己的私有库地址,使用私有库的 Podfile 如下。

use_frameworks!
sources = 'https://github.com/CocoaPods/Specs'
sources = 'https://git.oschina.net/skyfree666/TestRepos'
target 'TestLib_Example' do
  pod 'TestLib', :path => '../'
  target 'TestLib_Tests' do
    inherit! :search_paths

其中,第4~7步,可以使用以下流程代替

pod lib lint --verbose --sources='https://git.oschina.net/skyfree666/TestRepos.git,https://github.com/CocoaPods/Specs.git' --allow-warnings

5、添加tag,并提交代码
6、复制“.podspec”
.cocoapods/repos/TestRepos下以版本号(如0.1.0)创建文件夹,将TestLib.podspec复制到该文件夹下。

  • .podspec的详细配置
  • 二、类库打包

    1、安装cocoapod的打包插件

    sudo gem install cocoapods-packager
    

    2、执行以下命令,打包

    pod package TestLib.podspec --library --force
    
  • --library: 打包成.a文件,如果不加则打包成.framework文件
  • --force: 强制覆盖
  • 三、可能遇到的问题

    1、执行pod lib create TestLib报错

    2、执行pod lib lint报错

    ERROR | unknown: Encountered an unknown error (uninitialized constant REST::DisconnectedError

    解决方案:
    可能TestLib.podspec中的s.homepages.source不正确

    3、执行pod spec lint报错