远程私有库步骤

2020-07-26  本文已影响0人  qjsxq

创建

1、自己的远程私有库的索引库添加到 cocoapods的索引库

#pod repo add 名称  地址
pod repo add LQFMSpecs  https://github.com/qjsxq121/LQFMSpecs.git

2、 创建pod模版库

pod lib create LQFMBaseTest

3、将要抽离的写好的代码放入LQFMBase文件下的Classes文件中


Snip20200724_5.png

在Example中使用的话,pod install一下就可以
4、 创建远程私有库,将代码上传远程私有库,打tag,配置podspec,tag保持一致可以通过

pod spec lint

验证配置是否正确
5、将podspec文件push到自己的索引库

pod repo push LQFMSpecs LQFMBaseTest.podspec 

这里一开始我这边报了一个错误

Your configuration specifies to merge with the ref 'refs/heads/master'
from the remote, but no such ref was fetched.

最后解决办法是先去本地自己的索引库随便添加了一个文件夹里面放了一个文件先push 到远程


Snip20200725_7.png

然后再

pod repo push LQFMSpecs LQFMBaseTest.podspec 
//pod repo 可以查看本地索引库

才成功,也不知道为什么。
pod search LQFMBaseTest 就可以搜到自己的仓库了
5、在主工程使用的时候需要加上私有库地址,自己的和cocoapods 的都要加

source 'https://github.com/qjsxq121/LQFMSpecs.git'  // 自己
source 'https://github.com/CocoaPods/Specs.git'

然后pod install 就可以使用了

更新

1、更新Classes里面的代码
2、 修改LQFMBaseTest.podspec里面的version
3、上传代码,打tag 和 LQFMBaseTest.podspec保持一致
4、然后执行

pod repo push LQFMSpecs LQFMBaseTest.podspec 

有可能不通过可以通过忽略警告执行

pod repo push LQFMSpecs LQFMBaseTest.podspec --allow-warnings

5、主工程 pod 更新 (--no-repo-update 不更新本地索引库,时间太长) 就可以使用了

pod update --no-repo-update

依赖问题

如果自己的库有依赖其他第三方的库,需要在podspec添加

s.dependency  'AFNetworking'

拆分成子库

现在远程库里有Base、Category、Network、Tool,每次使用的时候都会将这4个全部下载下来。如果想单独使用就修改LQFMBaseTest.podspec文件 单独定义每一个功能的source_files

#s.source_files = 'LQFMBaseTest/Classes/**/*'
  s.subspec 'Base' do |b|
     b.source_files = 'LQFMBaseTest/Classes/Base/**/*'
   end

   s.subspec 'Category' do |c|
     c.source_files = 'LQFMBaseTest/Classes/Category/**/*'
   end

    s.subspec 'Network' do |n|
        n.source_files = 'LQFMBaseTest/Classes/Network/**/*'
        n.dependency 'AFNetworking'
    end

    s.subspec 'Tool' do |t|
        t.source_files = 'LQFMBaseTest/Classes/Tool/**/*'
    end

然后执行上面的更新步骤2、3、4
pod search LQFMBaseTest

  pod 'LQFMBaseTest', '~> 0.4.0'
   - Homepage: https://github.com/qjsxq121/LQFMBaseTest
   - Source:   https://github.com/qjsxq121/LQFMBaseTest.git
   - Versions: 0.4.0, 0.3.0, 0.2.0, 0.1.0 [LQFMSpecs repo]
   - Subspecs:
     - LQFMBaseTest/Base (0.4.0)
     - LQFMBaseTest/Category (0.4.0)
     - LQFMBaseTest/Network (0.4.0)
     - LQFMBaseTest/Tool (0.4.0)
(END)

使用

#pod 'LQFMBaseTest'
pod 'LQFMBaseTest/Category'

pod install 就可以单独使用Category了

上一篇 下一篇

猜你喜欢

热点阅读