iOS-CocoaPods安装远程私有仓库

目的:
远程, 是为了队员下载
私有, 是为了只有团队内部人员可以下载
创建步骤:

1.要在远程托管平台上创建一个远程私有库(这里我用码市作为远程代码管理工具,需要添加ssh公钥(略)).(https://git.coding.net/chongyingnvhai/FMBase.git), 把自己的三方库上传到远程私有库.

这个是官方提供的公共的索引库,所以我们的Spec的文件不能放在这里面.

1-0.png

查看本地仓库,发现只有一个master,所以添加一个我们自己的spec的索引库

wuxianlvzhoudeMacBook-Pro:~ Allison$ pod repo

master
- Type: git (master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/wuxianlvzhou/.cocoapods/repos/master

wuxianlvzhoudeMacBook-Pro:~ Allison$ pod repo add FMBase git@git.coding.net:chongyingnvhai/FMSpec.git
Cloning spec repo `FMBase` from `git@git.coding.net:chongyingnvhai/FMSpec.git`
wuxianlvzhoudeMacBook-Pro:~ Allison$ 

此时我们再查看,就可以看到两个了

wuxianlvzhoudeMacBook-Pro:~ Allison$ pod repo

FMBase
- Type: git (master)
- URL:  git@git.coding.net:chongyingnvhai/FMSpec.git
- Path: /Users/wuxianlvzhou/.cocoapods/repos/FMBase

master
- Type: git (master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/wuxianlvzhou/.cocoapods/repos/master

1-1.png

然后我们需要在远程代码托管上再创建一个,将本地库上传至远程私有库

1-3.png
2.cd进入到文件夹下,使用pod lib create <私有库名字>命令, 克隆下来

注意:如果pod lib create <私有库名字>出错的话,建议这里看下终端环境,如果没有错误,请直接跳过解决方案。

allisondeMacBook-Pro:~ allison$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]

如果你和我一样 是ruby2.5以上的环境,下面的命令执行讲话出现错误

/Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:27:in `<module:BuildSettingsArraySettingsByObjectVersion>': undefined method `to_set' for #<Array:0x007f925d88dc30> (NoMethodError) Did you mean? to_s
from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:8:in `<class:XCBuildConfiguration>' from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:4:in `<module:Object>'
from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:3:in `<class:Project>' from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:2:in `<module:Xcodeproj>' from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:1:in `<top (required)>'
from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/build_configuration.rb:194:in `<top (required)>' from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object.rb:521:in `<top (required)>' from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project.rb:5:in `<top (required)>'
from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Users/allison/Desktop/founderSpec/setup/ProjectManipulator.rb:30:in `run' from /Users/allison/Desktop/founderSpec/setup/ConfigureiOS.rb:73:in `perform' from /Users/allison/Desktop/founderSpec/setup/ConfigureiOS.rb:7:in `perform'
from /Users/allison/Desktop/founderSpec/setup/TemplateConfigurator.rb:85:in `run' from ./configure:9:in `<main>'

解决方案:
卸载一个已安装的ruby2.5高版本

$ rvm remove <版本号>
例:rvm remove 2.5.1

通过rvm list known 查看目前的所有ruby版本

ruby.jpg

选择低于ruby2.5的版本进行安装

$ rvm install 2.4.1

再次执行pod lib create <私有库名字>命令,克隆操作将不会出错。

wuxianlvzhoudeMacBook-Pro:~ Allison$ cd /Users/wuxianlvzhou/Desktop/remoteLib 
wuxianlvzhoudeMacBook-Pro:remoteLib Allison$ pod lib create FMBase
Cloning `https://github.com/CocoaPods/pod-template.git` into `FMBase`.
Configuring FMBase template.

------------------------------

To get you started we need to ask a few questions, this should only take a minute.

If this is your first time we recommend running through with the guide: 
 - http://guides.cocoapods.org/making/using-pod-lib-create.html
 ( hold cmd and double click links to open in a browser. )


What language do you want to use?? [ Swift / ObjC ]
 > Objc

Would you like to include a demo application with your library? [ Yes / No ]
 > Yes

Which testing frameworks will you use? [ Specta / Kiwi / None ]
 > None

Would you like to do view based testing? [ Yes / No ]
 > Yes

What is your class prefix?
 > AA

Running pod install on your new library.

Analyzing dependencies
Fetching podspec for `FMBase` from `../`
Downloading dependencies
Installing FBSnapshotTestCase (2.1.4)
Installing FMBase (0.1.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `FMBase.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.

[!] Automatically assigning platform ios with version 8.3 on target FMBase_Example because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

 Ace! you're ready to go!
 We will start you off by opening your project in Xcode
  open 'FMBase/Example/FMBase.xcworkspace'

To learn more about the template see `https://github.com/CocoaPods/pod-template.git`.
To learn more about creating a new pod, see `http://guides.cocoapods.org/making/making-a-cocoapod`.

3.此时Xcode会自动打开一个工程,找到pods文件,把Pods-->Development Pods-->XMGFMBase-->XMGFMBase-->Classes-->ReplaceMe.m文件删除,将三方替换过来.再次执行pod install即可.
1.png
4.现在需要把整个FMBase文件夹提交到远程私有库,包括里面的测试工程一起提交.
wuxianlvzhoudeMacBook-Pro:Example Allison$ cd /Users/wuxianlvzhou/Desktop/1.0本地库方案/remoteLib/XMGFMBase 
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    deleted:    FMBase/Classes/ReplaceMe.m

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    Example/Podfile.lock
    Example/Pods/
    Example/FMBase.xcworkspace/
    FMBase/Classes/Category/
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ git add .
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ git commit -m '**'
......

提交远程库前将FMBase.podspec文件修改

s.homepage = 'https://coding.net/u/chongyingnvhai/p/FMBase'
修改为:
s.homepage = 'https://git.coding.net/chongyingnvhai/FMBase.git'

提交前现在终端验证下本地文件有没有错误

wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ pod lib lint

 -> XMGFMBase (0.1.0)

FMBase passed validation.
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ 

按回车,此时会自动验证当前目录下的ΧⅩΧⅩ.podspec文件,并且验证里面的字段.看见FMBase passed validation即代表验证成功.
注意:这里的 s.source_files = 'FMBase/Classes/*/' 目录一定要是绝对的目录,也就是说与.podspec同级目录开始写路径.

1-6.png

将本地库与远程库关联,并且上传至远程库.

这里如果我们验证远程索引库的话会报如下错误,所以接下来我们需要给我们的库打tag.

wuxianlvzhoudeMacBook-Pro:FMBase Allison$ pod spec lint

 -> FMBase (0.1.0)
    - ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error.
[!] 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`.

5.给我们的库打tag,并推送至远程库.
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ git tag
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ git tag
0.1.0
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ git push --tags
Counting objects: 1, done.
Writing objects: 100% (1/1), 153 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To git.coding.net:chongyingnvhai/XMGFMBase.git
 * [new tag]         0.1.0 -> 0.1.0
6.验证远程仓库
wuxianlvzhoudeMacBook-Pro:FMBase Allison$ pod spec lint

 -> FMBase (0.1.0)

Analyzed 1 podspec.

FMBase.podspec passed validation.

7.远程验证通过后,将自己的索引库提交至远程 (把FMBase.podspec文件push到远程FMSpec私有库中.)
wuxianlvzhoudeMacBook-Pro:FMBase Allison$ pod repo push FMBase FMBase.podspec

Validating spec
 -> FMBase (0.1.0)

Updating the `FMBase' repo

Already up-to-date.

Adding the spec to the `FMBase' repo

 - [Add] FMBase (0.1.0)

Pushing the `FMBase' repo

To git.coding.net:chongyingnvhai/FMSpec.git
   07b51f6..7bafcc3  master -> master

自己的私有索引库

1-4.gif
1-5.png
8.在终端直接检索
wuxianlvzhoudeMacBook-Pro:FMBase Allison$ pod search FMBase

-> FMBase (0.1.0)
   FMBase框架
   pod 'FMBase', '~> 0.1.0'
   - Homepage: https://coding.net/u/chongyingnvhai/p/FMBase
   - Source:   https://git.coding.net/chongyingnvhai/FMBase.git
   - Versions: 0.1.0 [FMBase repo]

至此本地的三方库已经变成私有库了,我们来使用一下.

--------------------------------- 使用步骤: ----------------------------------

1.修改Podfile文件

use_frameworks!
target 'FMBase_Example' do
pod 'FMBase', :path => '../'
end
修改为
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'FMBase_Example' do
pod 'FMBase'
end

2.在终端执行pod install
wuxianlvzhoudeMacBook-Pro:Example Allison$ pod install
Analyzing dependencies
Downloading dependencies
Installing FMBase (0.1.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

此时我们的远程私有库就可以通过pod的形式导入项目来使用了.but,but,but,如果我们用的是GitHub上的开元三方呢,Podfile文件如下

source 'git@git.coding.net:chongyingnvhai/FMSpec.git'
use_frameworks!
target 'FMBase_Example' do
pod 'FMBase'
pod 'AFNetworking'
end

我们再次执行pod install的时候就会出现如下的错误

wuxianlvzhoudeMacBook-Pro:Example Allison$ pod install
Analyzing dependencies
[!] Unable to find a specification for `AFNetworking`

这是因为,我们执行pod install的时候是从我们自己的私有库里面搜索的,所以我们还需要将共有库的地址加进来.

source 'git@git.coding.net:chongyingnvhai/FMSpec.git'
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'FMBase_Example' do
pod 'FMBase'
pod 'AFNetworking'
end

这样再次执行就可以正确安装了.

wuxianlvzhoudeMacBook-Pro:Example Allison$ pod install
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (3.1.0)
Using FMBase (0.1.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
远程私有库的依赖+升级

以上完成了对远程私有库的设置,假如后期我们对该库有修改,或者增加了一些其它的功能,我们需要对远程的私有库进行升级即可.一般我们都会有Subspecs子库.例如我们熟知的AFNetworking

-> AFNetworking (3.1.0)
   A delightful iOS and OS X networking framework.
   pod 'AFNetworking', '~> 3.1.0'
   - Homepage: https://github.com/AFNetworking/AFNetworking
   - Source:   https://github.com/AFNetworking/AFNetworking.git
   - Versions: 3.1.0, 3.0.4, 3.0.3, 3.0.2, 3.0.1, 3.0.0, 3.0.0-beta.3,
   3.0.0-beta.2, 3.0.0-beta.1, 2.6.3, 2.6.2, 2.6.1, 2.6.0, 2.5.4, 2.5.3, 2.5.2,
   2.5.1, 2.5.0, 2.4.1, 2.4.0, 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0,
   2.1.0, 2.0.3, 2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 1.3.4,
   1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0RC2,
   1.0RC1, 0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [master repo]
   - Subspecs:
     - AFNetworking/Serialization (3.1.0)
     - AFNetworking/Security (3.1.0)
     - AFNetworking/Reachability (3.1.0)
     - AFNetworking/NSURLSession (3.1.0)
     - AFNetworking/UIKit (3.1.0)
升级远程私有库的步骤:

1.在工程中加入新的类别

1.png

2.在控制台执行pod install
3.修改FMBase.podspec文件里面的 s.version = '0.2.0'
3.重写打个tag 并push到远端( git push --tags )
4.此时代码已经升级完成.
5.升级pod里面的Spec版本,先验证通过

2.png
wuxianlvzhoudeMacBook-Pro:FMBase Allison$ pod spec lint

 -> FMBase (0.2.0)

Analyzed 1 podspec.

FMBase.podspec passed validation.

6.往本地私有索引库提交
在终端执行 pod repo push FMSpec FMBase.podspec

wuxianlvzhoudeMacBook-Pro:FMBase Allison$ pod repo push FMSpec FMBase.podspec

Validating spec
 -> FMBase (0.2.0)

Updating the `FMSpec' repo

Already up-to-date.

Adding the spec to the `FMSpec' repo

 - [Update] FMBase (0.2.0)

Pushing the `FMSpec' repo

To git.coding.net:chongyingnvhai/FMSpec.git
   c54796c..d3fde69  master -> master

在终端执行 pod search FMBase可以看到搜索出来的结果.

-> FMBase (0.3.0)
   FMBase框架
   pod 'FMBase', '~> 0.3.0'
   - Homepage: https://coding.net/u/chongyingnvhai/p/FMBase
   - Source:   https://git.coding.net/chongyingnvhai/FMBase.git
   - Versions: 0.3.0, 0.2.0, 0.1.0 [FMSpec repo]
   - Subspecs:
     - FMBase/Category (0.3.0)
     - FMBase/Base (0.3.0)
     - FMBase/Tool (0.3.0)
     - FMBase/Network (0.3.0)

这种对代码结构进行了归类,目录结构更加简洁明了.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,185评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,445评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,684评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,564评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,681评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,874评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,025评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,761评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,217评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,545评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,694评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,351评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,988评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,778评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,007评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,427评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,580评论 2 349

推荐阅读更多精彩内容