私有库

作者: 张_何 | 来源:发表于2019-07-29 18:24 被阅读0次

git.oschina.net 上创建两个私有库
ZJWFoundatinZJWFoundatinSpec,不选择语言,选择swift忽略文件,不要创建readme

终端操作

  • cd 到 ~/.cocoapods/repos 路径下
    ~$ cd ~/.cocoapods/repos
  • 本地创建 ZJWFoundationSpec 并关联远程的地址
    repos$ pod repo add ZJWFoundationSpec https://gitee.com/***/ZJWFoundationSpec.git
  • 输出
    Cloning spec repo ZJWFoundationSpec from https://gitee.com/***/ZJWFoundationSpec.git
    执行成功后如下图
    Snip20190729_3.png
  • 找到合适的路径
    repos$ cd ~/.
    ~$ cd Desktop/
  • 创建工程文件
    Desktop$ pod lib create ZJWFoundation
  • 输出
    Cloning https://github.com/CocoaPods/pod-template.git into ZJWFoundation . Configuring ZJWFoundation template.
...
What platform do you want to use?? [ iOS / macOS ]
 > ios

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

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

Which testing frameworks will you use? [ Quick / None ]
 > none

Would you like to do view based testing? [ Yes / No ]
 > yes
...
  • 删除classes文件夹下的ReplaceMe文件
    ~$ cd /Users/***/Desktop/ZJWFoundation/ZJWFoundation/Classes
    Classes$ rm -f ReplaceMe.swift
  • 创建一个文件夹 将需要的文件复制到文件夹中
    Classes$ mkdir Extension
    Classes$ cp /Users/***/Desktop/Bool+Extension.swift /Users/***/Desktop/ZJWFoundation/ZJWFoundation/Classes/Extension/
  • cd 到Example 文件夹下,执行pod install
    Classes$ cd /Users/***/Desktop/ZJWFoundation/Example
    Example$ pod install
  • 输出
Analyzing dependencies
····
[!] Automatically assigning platform `ios` with version `9.3` on target `ZJWFoundation_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`.
  • 打开 ZJWFoundation.podspec 文件,如下图修改


    Snip20190729_5.png
  • 切换到项目主路径下
    ZJWFoundation$ cd /Users/***/Desktop/ZJWFoundation
  • 校验本地文件的有效性
    ZJWFoundation$ pod lib lint --allow-warnings
  • 输出
 -> ZJWFoundation (0.1.0)
···
ZJWFoundation passed validation.
  • 给本地仓库添加远程(会有如下报错)
    ZJWFoundation$ git remote add origin https://gitee.com/***/ZJWFoundation.git
    ZJWFoundation$ git push origin master
  • 输出
To https://gitee.com/***/ZJWFoundation.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/***/ZJWFoundation.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  • 拉远程(会有如下报错,提示.gitignore有冲突)
    ZJWFoundation$ git pull origin master
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://gitee.com/***/ZJWFoundation
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories
ZJWFoundation$ git pull origin master --allow-unrelated-histories
From https://gitee.com/***/ZJWFoundation
 * branch            master     -> FETCH_HEAD
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.
  • 找到冲突文件,解决冲突
  • 解决完冲突再次提交
    ZJWFoundation$ git add .
    ZJWFoundation$ git commit -m "resloved conflict"
  • 再次拉取远程
    ZJWFoundation$ git pull origin master
  • 推送到远程
    ZJWFoundation$ git push origin master
  • 打标签并推送到远程,此处的标签号要和.podspec文件中的版本号一致
    git tag -m "0.1.0标签" -a 0.1.0
    ZJWFoundation$ git push --tags
  • 查看标签
    ZJWFoundation$ git tag
  • 输出
    0.1.0
  • 再次校验本地与远程文件的有效性
    ZJWFoundation$ pod spec lint --allow-warnings
  • 输出
 -> ZJWFoundation (0.1.0)
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file. (in target 'App')
Analyzed 1 podspec.
`ZJWFoundation.podspec passed validation.`
  • 向私有的spec Repo远程仓库中提交podspec
    ZJWFoundation$ pod repo push ZJWFoundationSpec ZJWFoundation.podspec --allow-warnings
  • 输出
Validating spec
 -> ZJWFoundation (0.1.0)
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file. (in target 'App')
Updating the `ZJWFoundationSpec' repo
Adding the spec to the `ZJWFoundationSpec' repo
 - [Add] ZJWFoundation (0.1.0)
Pushing the `ZJWFoundationSpec' repo
  • 执行成功后如下图


    Snip20190729_6.png
  • 查看第三方框架仓库源
    ZJWFoundation$ pod repo
  • 输出
master
- Type: git (master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/***/.cocoapods/repos/master

ZJWFoundationSpec
- Type: git (master)
- URL:  https://gitee.com/***/ZJWFoundationSpec.git
- Path: /Users/***/.cocoapods/repos/ZJWFoundationSpec

ZJWUIKitSpec
- Type: git (master)
- URL:  https://gitee.com/***/ZJWUIKitSpec.git
- Path: /Users/***/.cocoapods/repos/ZJWUIKitSpec

使用

  • 创建一个新的工程编写podfile文件


    Snip20190814_12.png
  • 执行pod install 命令

遇到的坑一

  • SJLoginModule 是我在制作的一个登陆的私有库,这个私有库中需要用到一个基础的私有库SJTools,配置好spec文件后去校验本地文件是否合法的时候执行pod lib lint --allow-warnings后,出现了如下报错
-> SJLoginModule (0.1.3)
    - ERROR | [iOS] unknown: Encountered an unknown error (CocoaPods could not find compatible versions for pod "SJTools":
  In Podfile:
    SJLoginModule (from `/Users/***/Desktop/SJLoginModule`) was resolved to 0.1.3, which depends on
      SJTools (~> 0.1.9.4)

None of your spec sources contain a spec satisfying the dependency: `SJTools (~> 0.1.9.4)`.

You have either:
 * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
 * mistyped the name or version.
 * not added the source repo that hosts the Podspec to your Podfile.

Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.) during validation.

[!] SJLoginModule did not pass validation, due to 1 error.
You can use the `--no-clean` option to inspect any issue.

这是在提示我找不到SJTools这个库,pod 在验证的时候默认是去公有库去找的,如果公有库找不到有没有添加私有库的源,就会提示找不到。所以这个时候我们再pod lib lint 的时候需要把私有库的spec仓库地址给加上
pod lib lint --sources=git@git.corp.***.cn:***iosgroup/***iospodspec.git,https://github.com/CocoaPods/Specs.git
如果你的库依赖多个私有库,那么就需要将所有私有库的地址都加上,每个地址之间用逗号分隔开,就像这样的形式
pod lib lint --sources=REPO_NAME1,REPO_NAME2,REPO_NAME3,https://github.com/CocoaPods/Specs.git --allow-warnings
其中https://github.com/CocoaPods/Specs.git是公有库repo的地址

遇到的坑二

制作的私有库中有一个第三方的SDK,这个sdk依赖系统的libresolv.9.tbd库,当时不知道,所以编译直接报错如下:

Snip20190823_7.png
然后百度得知需要添加libresolv.9.tbd库,然后便在demo中的target中添加了该库,可以编译还以报错,看到网上说的都是这个原因,以为自己添加错了。 Snip20190823_8.png
经过一番折腾之后才发现原来是要在SJLoginModule TARGET下添加,因为是在编译这个target的时候出现错误的
Snip20190823_9.png

注意: 每次pod install 后添加的依赖库都需要再重新添加

遇到的坑三

[!] The 'Pods-SJLoginModule_Example' target has transitive dependencies that include statically linked binaries: (LZNetwork and CleanJSON)

  • 解决方法:在podspec中加上这句 s.static_framework = true

遇到的坑四

error: linker command failed with exit code 1 (use -v to see invocation)
原因是在swift项目中依赖了一个oc 第三方库,导致链接的时候失败。
pod lib lint --sources=https://github.com/CocoaPods/Specs.git,git@git.***.cn:***iosgroup/***iospodspec.git --allow-warnings --skip-import-validation
在解决完上面的问题后,把本地的podspec文件推送到远程的时候同样会提示链接的错误

 SJLoginModule$ pod repo push plu-***iospodspec SJLoginModule.podspec --allow-warnings

Validating spec
 -> SJLoginModule (0.1.4)
    - WARN  | source: Git SSH URLs will NOT work for people behind firewalls configured to only allow HTTP, therefore HTTPS is preferred.
  ······
    - NOTE  | [iOS] xcodebuild:  clang: error: linker command failed with exit code 1 (use -v to see invocation)

这个时候我们同样需要加上 -skip-import-validation 命令
pod repo push ***-***iospodspec SJLoginModule.podspec --allow-warnings --skip-import-validation

相关文章

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

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

  • 创建私有库

    Part1私有索引库(存放.podSpec文件) 私有索引库分为本地私有索引库和远程私有索引库。 本地索引库 可以...

  • 组件化(第二篇)

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

  • [iOS模块式开发]例讲如何制作一个CocoaPods私有库

    10月23日更新 私有库A与私有库B之间的依赖处理:例如私有库B依赖于私有库A,在私有库B本地验证时: 会报错,提...

  • 创建pod私有库

    iOS创建私有库 1. 新建私有库 2.命令行创建本地私有库索引和远程私有库索引关联 pod repo add S...

  • iOS创建私有库

    iOS创建私有库 创建本地私有库索引和远程私有库索引关联 pod repo addSGSpecshttp://12...

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

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

  • 组件化开发(四)本地私有库

    通过本地私有库实现组件化开发 组件化开发分为本地私有库和远程私有库,这里我们先来学习如何通过本地私有库实现组件化的...

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

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

  • ios 私有库创建

    一.创建私有库的索引库 1.git上创建私有索引库 拿到私有库的索引地址(https://github.c...

网友评论

      本文标题:私有库

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