CocoaPods+Gitee 制作私有库过程以及错误总结
<p> </p><p><strong>前言</strong></p>
<hr>
<p> </p>
<p> 最近由于要做组件化,所以就顺便看了看私有库的制作,整体上制作的过程是比较简单的,但有一些点你注意到的话会在制作过程会少去很多的麻烦,在网上搜的制作过程的文章是一大把,但当你真的遇到一些问题的时候在去找答案有些就会比较困难,所以出于这样的一个初衷我在这里就把自己整个制作过程记录下来,以及这这些过程中你需要注意的点全都整理出来,保证这篇文章能完全把整个过程说清楚,让你看着这篇文章能够完全理解过程和每一步我们都做了什么。</p>
<p> </p>
<p><strong>一:先说说关于CocoaPods </strong></p>
<hr>
<p> </p>
<p> 快捷键: command + shift + g ,再输入 ~/.cocoapods/repos 就可以查看我们Cocoapods-repo的文件夹</p>
<p><code class="diff language-diff" data-lang="diff"><span class="gi"> <strong>下面我制作的过程中CocoaPods的版本是 1.9.1 </strong></span></code></p>
<p> 1、CocoaPods 1.8 Beta is Here!</p>
<p> 2、CocoaPods|安装流程与使用</p>
<p> 3、CocoaPods 都做了什么</p>
<p> </p>
<p><strong>二:首先得有两个远程库</strong></p>
<hr>
<p> </p>
<p> 这里先解释一下为什么我们需要两个远程库,假设这两个库分别为仓库A 和仓库B, <strong>A-我们用来存放我们制作私有库项目的代码</strong>, <strong>B-我们用来存放我们的私有库</strong>。我想这句话应该是解释清楚了为什么我么需要两个远程库了,当然你要说你不需要把你制作私有库的代码上传到远程库那也就意味这你不需要远程库A了,但这样的确是不行的,这个我们后面再说。</p>
<p> 我们用码云为例子,创建两个远程私有库,<strong>填写名称什么的我就不说了</strong>,需要留意的也就下面两个地方:</p>
<p><img src="https://img2020.cnblogs.com/blog/739006/202004/739006-20200410102642682-794663168.png" alt="" width="720" height="529" style="display: block; margin-left: auto; margin-right: auto"></p>
<p> 建议还是使用Readme 文件初始化仓库,这样我们后面使用 MarkDown 语言来写使用说明会比较好,这也是现在很多三方在使用的方式。</p>
<p> </p>
<p><strong>三:制作私有库</strong></p>
<hr>
<p> </p>
<p> 这个制作过程我们按照步骤的形式往下说:</p>
<p> 1、承接上面 A和B两个远程库的逻辑,比如说你是用远程库B来存放私有库,那你就先需要把B添加到你CocoaPods的本地repo中,终端打开准备干活了,命令如下:</p>
<p> <strong>pod repo add B私有库名称 B私有库码云地址</strong> <br></p>
<p> <strong>完成上面的步骤之后还是按前面我们说的你进入到CocoaPods 的repo中去看看就应该有了远程库B啦~</strong></p>
<p> 2、在你本地创建一个文件夹用于存放私有库项目省略......</p>
<p> 3、cd到你上面创建的文件路径下面,创建你需要制作私有库的项目,执行下面命令:pod lib create 私有库项目名称 【建议这个名称最好不要和你私有库名称重复-便于区分】</p>
<p> <img src="https://img2020.cnblogs.com/blog/739006/202004/739006-20200410105900286-1884457984.png" alt="" width="697" height="410" style="display: block; margin-left: auto; margin-right: auto"></p>
<p> </p>
<p> 4、如上图所示,我创建了三个私有库项目用来制作私有库,接下来要做的就是在替换文件或者是自己创建文件来写你的私有库项目代码了,要是你已经写好了你私有库的代码,那你就直接进入ZXTestOCUIKit路径下面的 Class文件进行一个替换,这里我们补充一点就是关于文件分层的问题,<strong>假如你在Class下面要把你的文件分别放到两个文件下面,不是说我们直接放进去就可以了,这里涉及到podspec文件的设置问题</strong>,这里你先有个印象,具体的怎么处理我们在说podspec文件修改的时候集中说。</p>
<p> </p>
<p><img src="https://img2020.cnblogs.com/blog/739006/202004/739006-20200410112511424-525124814.png" alt="" width="696" height="417" style="display: block; margin-left: auto; margin-right: auto"></p>
<p> </p>
<p> 5、进入到 Example 路径下面直接打开项目, 这里就一点,<strong>不管前面Class你是替换的文件还是你打开项目之后创建文件修改,改动完了之后都记得 pod install 一下!</strong>不然你在 Example 可能找不大你需要的文件。<strong>其实这里也有一个问题的,就是你把文件拉进来之后不修改好</strong><strong>podspec 文件,执行 pod install 之后发现添加到项目中的文件引用不见了,我在尝试的时候就有这个问题,在添加Assest资源的时候也有这个问题,你要是遇到这个问题就找下面修改<strong>podspec文件的内容设置要分层路径再执行 pod install。</strong></strong></p>
<p><strong> </strong>6、修改你的podspec文件<strong>,</strong>打开项目找到最上面的 .podspec文件,文件里面修改注意的点我都写在注释里面了。</p>
<div class="cnblogs_code">
<pre>Pod::Spec.<span style="color: rgba(0, 0, 255, 1)">new</span> <span style="color: rgba(0, 0, 255, 1)">do</span> |s|<span style="color: rgba(0, 0, 0, 1)">
s.name </span>= <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">ZXTestOCUIKit</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
#版本号
s.version </span>= <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">0.0.5</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
#摘要
s.summary </span>= <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">A Test Privity Kit About ZXTestOCUIKit.</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
# This description </span><span style="color: rgba(0, 0, 255, 1)">is</span><span style="color: rgba(0, 0, 0, 1)"> used to generate tags and improve search results.
# </span>* Think: What does it <span style="color: rgba(0, 0, 255, 1)">do</span>? Why did you write it? What <span style="color: rgba(0, 0, 255, 1)">is</span> the focus?<span style="color: rgba(0, 0, 0, 1)">
# </span>* Try to keep it <span style="color: rgba(0, 0, 255, 1)">short</span><span style="color: rgba(0, 0, 0, 1)">, snappy and to the point.
# </span>*<span style="color: rgba(0, 0, 0, 1)"> Write the description between the DESC delimiters below.
# </span>* Finally, don<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">t worry about the indent, CocoaPods strips it!</span>
<span style="color: rgba(0, 0, 0, 1)">
s.description </span>= <<-<span style="color: rgba(0, 0, 0, 1)">DESC
TODO: ZhangXu A Test Privity Kit About ZXTestOCUIKit.
DESC
# 你的主页地址 填个能访问的 不然可能检验的时候报错
s.homepage </span>= <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">https://gitee.com/MrRisingSun</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
# s.screenshots </span>= <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">www.example.com/screenshots_1</span><span style="color: rgba(128, 0, 0, 1)">'</span>, <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">www.example.com/screenshots_2</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
s.license </span>= { :type => <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">MIT</span><span style="color: rgba(128, 0, 0, 1)">'</span>, :file => <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">LICENSE</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> }
# 作者
s.author </span>= { <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">Zhangxu</span><span style="color: rgba(128, 0, 0, 1)">'</span> => <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">zhangxu@pipipifa.com</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> }
# 你制作私有库项目的远程地址 A
s.source </span>= { :git => <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">https://gitee.com/MrRisingSun/ZXTsetOCUIKit.git</span><span style="color: rgba(128, 0, 0, 1)">'</span>, :tag =><span style="color: rgba(0, 0, 0, 1)"> s.version.to_s }
# s.social_media_url </span>= <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">https://twitter.com/<TWITTER_USERNAME></span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
# 最低版本
s.ios.deployment_target </span>= <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">9.0</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
# 文件层级分类
#s.source_files </span>= <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">ZXTestOCUIKit/Classes/**/*</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
# 要是文件有分层 就这样写
s.subspec </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">ZXLoadingView</span><span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">do</span> |ss|<span style="color: rgba(0, 0, 0, 1)">
ss.source_files </span>= <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">ZXTestOCUIKit/Classes/ZXLoadingView/*.{h,m}</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
end
s.subspec </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">ZXUIView</span><span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">do</span> |ss|<span style="color: rgba(0, 0, 0, 1)">
ss.source_files </span>= <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">ZXTestOCUIKit/Classes/ZXUIView/*.{h,m}</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
end
# 资源
s.resource_bundles </span>=<span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">ZXTestOCUIKit</span><span style="color: rgba(128, 0, 0, 1)">'</span> => [<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">ZXTestOCUIKit/Assets/*.{png,json,xcassets}</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">]
}
# s.public_header_files </span>= <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">Pod/Classes/**/*.h</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
# s.frameworks </span>= <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">UIKit</span><span style="color: rgba(128, 0, 0, 1)">'</span>, <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">MapKit</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
# 依赖库
s.dependency </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">AFNetworking</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
s.dependency </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">JSONModel</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
s.dependency </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">lottie-ios</span><span style="color: rgba(128, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">2.5.3</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> # 指定版本
s.dependency </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">ZXTest2OCUIKit</span><span style="color: rgba(128, 0, 0, 1)">'</span></pre>
</div>
<p> 注意:里面涉及到资源引用路径的时候稍微留意下,我在我的项目中引用了一个JSON格式文件的动画资源,你要有别的格式的资源引用方式是一样的。</p>
<p> <strong> 还是那句,记得你要是修改了Class的文件,在写Example 的时候记得 pod install 一下使用</strong></p>
<p> 7、上面这些就基本上该修改的也都修改好了,在进行后面的操作的时候,我们先本地校验一下,按照我上面的创建 你应该在 ZXTestOCUIKit 文件下执行本地校验,也就是在Example的这一层路径下,别在Example下校验 ,执行 <strong>pod lib lint</strong>。本地检验这一步也是错误比较多的一步,这里会检验出创建的各种各样的问题,你要有问题在后面错误的集中处理中看看有没有可以帮助到你的,还有问题可以在我主页QQ找我。</p>
<p> 8、后面的操作就是一些关于git的操作, 我们先关联git: git remote add origin 远程仓库地址A </p>
<p> 9、然后拉去一下代码,git pull origin master --allow-unrelated-histories【unrelated-histories-允许合并不相关的历史内容】</p>
<p> 10、上传制作私有库的项目代码到远程仓库A:</p>
<p> git add .</p>
<p> git commit -m'描述'</p>
<p> git pull origin master</p>
<p> git push origin master</p>
<p> 11、打标签,在最后制作私有库之前我们需要给它打个标签,在每一次我们修改文件更新私有库上传代码的时候我们都要进行这一步的,<strong>并且保证你打的标签和你本地 podspec文件的版本号是一致的</strong>。</p>
<p> git tag -a 0.0.1 (比如是这个版本) -m '0.0.1'(m 里面的内容都是描述内容)</p>
<p> git push --tags 标签打完 你也可以通过 git tag 查看一下是不是你这个标签</p>
<p> 12、最后就是私有库制作远程检验</p>
<p> 执行: pod spec lint </p>
<p> 这一步也是一个错误集中爆发地,后面我也在经理总结这里有的错误,其实整个过程不是很复杂,只要自己动手多走几遍,慢慢的也就都理解不在觉得困难。</p>
<p> 13、上传私有库到我们Cocoapods的repo</p>
<p> 还记得最开始时候第一步我们添加的 repo B 吗?我们现在把我们制作的私有库提交到这个远程仓库中,执行下面命令:</p>
<p> pod repo push Cocoapods的repo名称 你私有库的项目的podspec名称【记得带上.podspec】</p>
<p> 走到这一步就算是我们的私有库主要的我们制作完了,下面我们要说的这就是整个过程中你可能也会遇到的问题,其实真正让我们纠结的从来都不是过程,而是这过程中遇到的各种的问题,我甚至连我Cocoapods都重装过,所以说有啥问题慢慢解决就可以了,终究你还是会成功的。</p>
<p> 14、要是用我们的私有库记得更新下我们Cocoapods的私有库Repo:</p>
<p> pod repo update 私有库repo</p>
<p> </p>
<p><strong>四:遇到的问题</strong></p>
<hr>
<p> </p>
<p> <strong>1、使用问题:</strong></p>
<p> <1>: 在你执行完上面13步之后可以 pod secrch '私有库' ,这地方在 1.9.1 这个版本失败的概率还是有的,我就经常失败,要是你确保你的步骤没问题,你在Cocoapods的repo 当中也确实能看你的私有库,<strong>那就跳过这边一步</strong>,不要去网上找 pod search 失败,你会发现答案很多可就是不是和现在这个流程,我在最前面说过 不要去采用删除master源这个方式!</p>
<p> <2>: 为什么我的swift私有库找不到方法、文件等等呀,我制作过程没问题呀,当然这一步可能你在开始写 Example 的时候也会有这个问题,它的答案就是 <strong>权限问题</strong>!<strong>swift 版本你要暴露的方法或者类什么的要使用open权限</strong>,我以为 public 默认的是没问题的,结果是有问题!你可以找那些swift版本的三方库就能发现是这个问题!</p>
<p> </p>
<p> <strong>2、本地检验额问题:</strong></p>
<p> <1>: 有警告检验不通过,就像下面这个一样。</p>
<p><img src="https://img2020.cnblogs.com/blog/739006/202004/739006-20200410150408456-2140277571.png" alt="" width="768" height="485" style="display: block; margin-left: auto; margin-right: auto"></p>
<p> 解决办法:</p>
<p> 其实最直接的办法就是你直接执行 pod lib lint --allow-warnings 允许警告 ,但要是细节处理这几个警告提挺有意思的,下面我们分析一下上面的三条警告:</p>
<p> 1、摘要写的太差了,就是连敷衍了事那种都没做的地步,哈哈哈哈。。。当然要是你的摘要写的比描述都多,你试试 😼</p>
<p> 2、检查一下写的主页地址还是项目地址有地方是有问题的,也就是连接不可用。所以我们前面雨说过主页地址写一个可以用的地址,百度都行,保证能正常访问,项目地址就写你远程项目仓库的地址,被填错了。</p>
<p> 3、第三个你上网去搜还能找出很多答案,有制作文件的等等,其实简单点你指定一下swift的版本就可以了: s.swift_version = '4.0'</p>
<p><span style="background-color: rgba(255, 255, 255, 1); color: rgba(255, 0, 0, 1)"> <strong style="color: rgba(255, 0, 0, 1)"><2>: 我找不到答案的问题 私有库相互依赖本地检验不过的问题 Returuned an unsuccessful exit code</strong></span></p>
<p><span style="background-color: rgba(255, 255, 255, 1); color: rgba(255, 0, 0, 1)"><strong> </strong><span style="color: rgba(0, 0, 0, 1)">这个问题我还真的是纠结了很久了,比如说你现在有叫做 Zhangxu1 和 Zhangxu2 的两个私有库,然后你在 Zhangxu2中要使用一些Zhangxu1的东西,你把他们都放在一个叫zhangxu的 cocoapods repo 下面,这时候你2依赖1,然后本地检验是捕获通过的,错误如下:</span></span></p>
<p><span style="background-color: rgba(255, 255, 255, 1); color: rgba(255, 0, 0, 1)"><span style="color: rgba(0, 0, 0, 1)"><img src="https://img2020.cnblogs.com/blog/739006/202004/739006-20200410152544870-1738810007.png" alt="" width="760" height="275" style="display: block; margin-left: auto; margin-right: auto"></span></span></p>
<p> 说实话,按照上面的逻辑我暂时真的没找到怎么解决,当然你可以说不要有依赖关系就可以了,这样肯定是没问题的,<strong>我纠结的点可能变成是不是不能这样依赖,就两个私有库之间</strong>!如果有知道答案的小伙伴也请指教我一下,我也很想知道答案、原因!!</p>
<p> 补充:</p>
<p> 后面使用中发现两个私有库在相互依赖的情况下要进行校验(包括本地和远程)你是需要带上 source 源的,具体的Demo如下:</p>
<div class="cnblogs_Highlighter">
<pre class="brush:csharp;gutter:true;">pod lib lint --sources=http://192.168.1.92/ice/PPSpecs.git,https://cdn.cocoapods.org/
</pre>
</div>
<p> 前面的源是你CocoaPods中的repo地址,我这个后面是还依赖了第三方,需要指定 CocoaPods的trunk源地址。</p>
<p> <strong> 3、远程校验问题:</strong></p>
<p> 你有依赖别的第三方库, 直接使用 pod spec lint 检验不行,那就试着加上源地址试试吧:</p>
<p><img src="https://img2020.cnblogs.com/blog/739006/202004/739006-20200410153526302-441190937.png" alt="" width="745" height="448" style="display: block; margin-left: auto; margin-right: auto"></p>
<p> </p>
<p> </p>
<p> <strong>4、还有许多会是一些关于 CocoaPods 的问题</strong></p>
<p> 我在前面有说过我利用一个json格式的文件,其实是用来做动画的,然后我尝试导入 lottie-ios 结果.....一直报下面这个错,然后上网找呀找,找呀找答案找的我睡着了还没解决,结果回到公司再次尝试。得到的结论<strong>就是应该是我网络差!┭┮﹏┭┮</strong></p>
<p><img src="https://img2020.cnblogs.com/blog/739006/202004/739006-20200410154215545-1542411092.png" alt="" width="749" height="257" style="display: block; margin-left: auto; margin-right: auto"></p>
<p> </p>
<p> 当然还有许许多多的问题,只不过我写这篇文章的时候是我忙完这些后面一个星期了,有些我记得也是模棱两可了!记性差.......</p>
<p> 总结就暂时这么多吧, 在整个私有库的使用过程中我相信关于它的问题我还是会遇到很多的,我再回来补充!</p>
<p> </p>
</div>
<div id="MySignature" role="contentinfo">
## 努力做一个合格的程序员。<br><br>
来源:https://www.cnblogs.com/zhangxiaoxu/p/12591897.html
頁:
[1]