git.oschina.net 上创建两个私有库
ZJWFoundatin 和 ZJWFoundatinSpec,不选择语言,选择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
执行成功后如下图
- 找到合适的路径
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 文件,如下图修改
- 切换到项目主路径下
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
-
执行成功后如下图
- 查看第三方框架仓库源
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文件
执行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
库,当时不知道,所以编译直接报错如下:
然后百度得知需要添加
libresolv.9.tbd
库,然后便在demo中的target中添加了该库,可以编译还以报错,看到网上说的都是这个原因,以为自己添加错了。
经过一番折腾之后才发现原来是要在
SJLoginModule
TARGET下添加,因为是在编译这个target的时候出现错误的注意: 每次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