美文网首页
远程私有库

远程私有库

作者: 曹来东 | 来源:发表于2019-04-10 15:16 被阅读0次
image.png
  • 远程索引库克隆到本地 pod repo add LibName LibURL
  • 本地文件夹存放私有库项目
  • 进入这个路径执行pod lib create LibName创建相关文件测试项目 spec文件等
  • 进入replaceMe路径,将文件替换成库文件
  • 进入测试工程podfile路径执行pod install添加库文件进行测试
  • 修改podspec文件并验证pod lib lint pod spec lint
  • 关联远程仓库git remote add origin 远程代码仓库地址(不是spec地址)这是两个地址,一个存放代码库,一个存放spec文件.
  • git pull origin master --allow-unrelated-histories把两段不相干的 分支进行强行合并
git status
git add .
git status
git commit -m "强行将本地分支和远程分支相关联,产生冲突"
git push
git push --set-upstream origin master
  • 添加tag,一般与version相对应,并推送到远程git push --tags
  • 验证spec文件.pod lib lint pod spec lint
  • podSpec文件提交到自己本地的私有spec库.push到哪里去了???
    pod repo push 推送到哪个repo中 xxx.podspec
  • podSpec文件推送到本地私有库的同时,私有库会将podSpec自动推送到远程仓库.
    image.png
  • pod search LibName 检索该框架.
  • 切换库源,执行pod install
    image.png
  • 将整个库文件项目推送到远程代码仓库git push
image.png

1.进入主工程所在目录

image.png
CLD:~ caolaidong$ cd /Users/caolaidong/Desktop/远程私有库/remoteLib
CLD:remoteLib caolaidong$ pod lib create RemoteBase
Cloning `https://github.com/CocoaPods/pod-template.git` into `RemoteBase`.
Configuring RemoteBase template.

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

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

2019-04-11 12:27:56.710 defaults[3763:929842]
The domain/default pair of (org.cocoapods.pod-template, HasRunbefore) does not exist
If this is your first time we recommend running through with the guide:
 - https://guides.cocoapods.org/making/using-pod-lib-create.html
 ( hold cmd and click links to open in a browser. )

 Press return to continue.


What platform do you want to use?? [ iOS / macOS ]
 > iOS

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 ]
 > no

What is your class prefix?
 > LD

Running pod install on your new library.

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

[!] Please close any current Xcode sessions and use `RemoteBase.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

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

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

2. 将目标pod文件放入如下路径,删除ReplaceMe.m

image.png

进入Example路径,为事例工程添加库依赖

image.png
CLD:remoteLib caolaidong$ cd /Users/caolaidong/Desktop/远程私有库/remoteLib/RemoteBase/Example
CLD:Example caolaidong$ pod install
Analyzing dependencies
Fetching podspec for `RemoteBase` from `../`
Downloading dependencies
Using RemoteBase (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.
CLD:Example caolaidong$

3.将文件提交到远程仓库

  • 远程spec仓库已经创建,里面只有ignore文件
  • 远程spec仓库已经添加到本地pod repo add specName 项目地址
  • 自己的pod分类项目已经开发完成
  • 将自己开发的项目推送到远程

1.进入远程库路径,添加并提交

image.png
CLD:Example caolaidong$ CD /Users/caolaidong/Desktop/远程私有库/remoteLib/RemoteBase
CLD:Example caolaidong$ GIT ADD .
fatal: cannot handle ADD as a builtin
CLD:Example caolaidong$ git add .
CLD:Example caolaidong$ git commit -m "pod库完成"

2.检查spec文件

  • pod lib lint 本地验证通过
CLD:RemoteBase caolaidong$ pod lib lint

 -> RemoteBase (0.1.0)
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description

RemoteBase passed validation.//通过验证
  • pod spec lint远程验证失败
CLD:RemoteBase caolaidong$ pod spec lint

 -> RemoteBase (0.1.0)
    - ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://dev.tencent.com/u/Caolaidong/p/XMGFMSpecs/git/tree/master /var/folders/8l/hqgr6fms2_l3b2r546c87k540000gq/T/d20190411-4772-1q2fnxi --template= --single-branch --depth 1 --branch 0.1.0

Cloning into '/var/folders/8l/hqgr6fms2_l3b2r546c87k540000gq/T/d20190411-4772-1q2fnxi'...
remote: 404 page not found
fatal: repository 'https://dev.tencent.com/u/Caolaidong/p/XMGFMSpecs/git/tree/master/' not found
) during validation.

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error.
CLD:RemoteBase caolaidong$

失败原因:本地验证不会验证 spec文件中的s.source里面有tag标记,我们没有添加tag标记.所以会报错.
s.source = { :git => 'https://dev.tencent.com/u/Caolaidong/p/XMGFMSpecs/git/tree/master', :tag => s.version.to_s }

3.打标签之前,需要远程仓库有代码.需要将代码退送到远程仓库

  • 本地仓库和远程仓库做关联
git push origin master
To https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
CLD:RemoteBase caolaidong$ git pull origin master
From https://git.dev.tencent.com/Caolaidong/XMGFMSpecs
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

git pull 失败 ,提示:fatal: refusing to merge unrelated histories

其实这个问题是因为 两个 根本不相干的 git 库, 一个是本地库, 一个是远端库, 然后本地要去推送到远端, 远端觉得这个本地库跟自己不相干, 所以告知无法合并

具体的方法, 一个种方法: 是 从远端库拉下来代码 , 本地要加入的代码放到远端库下载到本地的库, 然后提交上去 , 因为这样的话, 你基于的库就是远端的库, 这是一次update

第二种方法:
使用这个强制的方法

git pull origin master --allow-unrelated-histories
后面加上 --allow-unrelated-histories , 把两段不相干的 分支进行强行合并

git status
git add .
git status
git commit -m "强行将本地分支和远程分支相关联,产生冲突"
git push
git push --set-upstream origin master

git pull origin master --allow-unrelated-histories
From https://git.dev.tencent.com/Caolaidong/XMGFMSpecs
 * branch            master     -> FETCH_HEAD
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.
CLD:RemoteBase caolaidong$ git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

    both added:      .gitignore

no changes added to commit (use "git add" and/or "git commit -a")
CLD:RemoteBase caolaidong$ git add .
CLD:RemoteBase caolaidong$ git status
On branch master
All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:

    modified:   .gitignore

CLD:RemoteBase caolaidong$ git commit -m "强行将本地分支和远程分支相关联,产生冲突"
[master a3a88b9] 强行将本地分支和远程分支相关联,产生冲突
CLD:RemoteBase caolaidong$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

CLD:RemoteBase caolaidong$ git push --set-upstream origin master
Enumerating objects: 93, done.
Counting objects: 100% (93/93), done.
Delta compression using up to 8 threads
Compressing objects: 100% (81/81), done.
Writing objects: 100% (91/91), 28.50 KiB | 2.85 MiB/s, done.
Total 91 (delta 26), reused 0 (delta 0)
To https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git
   b92b806..a3a88b9  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
CLD:RemoteBase caolaidong$

4打标签

tag值要与PodSpec文件中的version版本相同

CLD:RemoteBase caolaidong$ git tag
CLD:RemoteBase caolaidong$ open .
CLD:RemoteBase caolaidong$ git tag 0.1.0
CLD:RemoteBase caolaidong$ git tag
0.1.0
CLD:RemoteBase caolaidong$ git push --tags
Total 0 (delta 0), reused 0 (delta 0)
To https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git
 * [new tag]         0.1.0 -> 0.1.0
CLD:RemoteBase caolaidong$

5.检测spec文件配置

pod spec lint

 pod spec lint

 -> RemoteBase (0.1.0)
    - ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://dev.tencent.com/u/Caolaidong/p/XMGFMSpecs/git/tree/master /var/folders/8l/hqgr6fms2_l3b2r546c87k540000gq/T/d20190411-6427-vl66ac --template= --single-branch --depth 1 --branch 0.1.0

Cloning into '/var/folders/8l/hqgr6fms2_l3b2r546c87k540000gq/T/d20190411-6427-vl66ac'...
remote: 404 page not found
fatal: repository 'https://dev.tencent.com/u/Caolaidong/p/XMGFMSpecs/git/tree/master/' not found
) during validation.

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error.
CLD:RemoteBase caolaidong$  pod spec lint

Username for 'https://git.coding.net': 1026190993@qq.com
Password for 'https://1026190993@qq.com@git.coding.net':
 -> RemoteBase (0.1.0)
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description

Analyzed 1 podspec.

RemoteBase.podspec passed validation.

CLD:RemoteBase caolaidong$

通过验证表示所有配置都正常.只需将spec文件提交到自己私有索引仓库即可.

6.查看当前索引库

pod repo

CLD:RemoteBase caolaidong$ pod repo

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

specName
- Type: git (master)
- URL:  https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git
- Path: /Users/caolaidong/.cocoapods/repos/specName

2 repos
CLD:RemoteBase caolaidong$

7. 将podspec文件提交到远程私有库

pod repo push specName RemoteBase.podspec
本地又两个索引哭一个是官方CocoaPods,另一个是私有的 specName,我们现在是将RemoteBase.podspec提交到我们的私有库specName中.

2.修改Example项目中的.podspec文件

pod repo And pod repo list

CLD:~ caolaidong$ pod repo

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

1 repo
CLD:~ caolaidong$ pod repo list

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

1 repo
CLD:~ caolaidong$

添加私有仓库

pod repo add specName 项目地址

CLD:~ caolaidong$ pod repo add specName https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git
Cloning spec repo `specName` from `https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git`
Username for 'https://git.dev.tencent.com': 1026190993@qq.com
Password for 'https://1026190993@qq.com@git.dev.tencent.com':
CLD:~ caolaidong$

可以看到添加了cocoapods官方以外的specName仓库

image.png

公钥私钥路径

CLD:~ caolaidong$ ssh-keygen//指令
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/caolaidong/.ssh/id_rsa):
/Users/caolaidong/.ssh/id_rsa already exists.//已经存在是否覆盖
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase)://密码
Enter same passphrase again://再次输入密码
Your identification has been saved in /Users/caolaidong/.ssh/id_rsa.
Your public key has been saved in /Users/caolaidong/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:5zI2/a6cEBM9F/kngJrnNdejMNt+ruoGUva4/j/ZiWU caolaidong@CLD.local
The key's randomart image is:
+---[RSA 2048]----+
|           ...   |
|         .. o.   |
|        .oo .o . |
|        o+.=o +.o|
|        So+.=o.o.|
|       . O.o o E |
|        B = . * .|
|       . B + = + |
|        ..B*=o=. |
+----[SHA256]-----+
CLD:~ caolaidong$
image.png

相关文章

  • 组件化(第二篇)

    组件化 一、本地私有库方案优化二、远程私有库三、如何使用远端私有库四、远程私有库的升级五、远程私有库依赖问题六、远...

  • iOS--本地私有库和远程私有库(三) --- ⅰ

    (三)敲重点!!远程私有库来了! ⅰ.远程私有库演示(本篇) ⅱ.远程私有库升级+优化 铺垫一:Category文...

  • iOS组件化开发远程私有库

    一、本地化私有库 工程创建好之后可以用作本地私有库,通过path来引入本地私有库 二、远程私有库 创建远程私有库,...

  • iOS--本地私有库和远程私有库(三) --- ⅱ

    (三)敲重点!!远程私有库来了! ⅰ.远程私有库演示 ⅱ.远程私有库升级+优化(本篇) 铺垫:本篇中的一些文件命名...

  • 组件化三:远程私有库

    远程私有库跟本地私有库的区别就是 先看看那远程私有库的原理 先创建一个远程的库,把本地的库关联到远程的库中,然后修...

  • 组件化创建远程私有库笔记

    1、创建远程私有库、远程私有Spec库2、创建私有库模板pod lib caeate 库名字3、将文件拖到clas...

  • iOS-组件化开发

    一、创建远程私有索引库 1. 创建远程私有索引库,然后复制仓库的地址 2. 打开终端,将远程私有库关联到本地 ...

  • iOS 组件化开发(二):子库和私有库升级与维护

    iOS 组件化开发(一):远程私有库的基本使用已经实战演示了远程私有库的基本操作。本文说下远程私有库的更新与子库。...

  • iOS CocoaPods私有库

    远程私有库就可以方便的解决以上的问题,制作远程私有库分为以下几个步骤: 创建私有 Git 远程仓库; 创建私有 C...

  • 组件化之创建私有远程库

    一.创建私有远程索引库 创建一个私有远程仓库主要的步骤如下: 创建远程索引库和私有组件库仓库 将远程索引库添加到本...

网友评论

      本文标题:远程私有库

      本文链接:https://www.haomeiwen.com/subject/gwdniqtx.html