参考资料:http://www.jianshu.com/p/9e2c7a7c1211html
私有库A与私有库B之间的依赖处理:
例如私有库B依赖于私有库A,在私有库B本地验证时:ios
pod lib lint
会报错,提示找不到私有库A。
执行命令为:git
pod lib lint --sources='http://[privateLibName]/cocoaspecs.git,https://github.com/CocoaPods/Specs.git'
关键词:库、模块式开发、CocoaPods、私有库、
工具:终端、git、CocoaPods
步骤总结:
一、打开终端,进入要创建私有库项目工程的路径,并执行pod库工程建立命令行
二、进入咱们的Example项目工程,执行安装CocoaPods项目命令行
三、添加库源码文件
四、书写CocoaPods配置文件LATAlert.podspec(建议使用Atom + cocoa-pods-ruby-snippets插件来编辑该文件)
五、建立私有库git地址,并完善.podspec配置文件
六、再次进入咱们的Example文件,执行pod更新指令,安装本地库源码
七、添加样例代码,运行样例测试
八、本地pod配置文件验证
九、项目工程发布tag 0.0.1
十、私有库发布
十一、验证发布的私有库
涉及到的命令行:
Git:github
Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git remote add origin https://git.oschina.net/KKLater/LATAlert.git Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git add . Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git commit -a -m "0.0.1" Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git pull origin master Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git push origin master Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git tag 0.0.1 Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git push origin 0.0.1
Pod:ruby
--allow-warningsLater@localhost:~/Desktop/私有库建立教程$ pod lib create LATAlert Later@localhost:~/Desktop/私有库建立教程/LATAlert/Example$ pod install --no-repo-update Later@localhost:~/Desktop/私有库建立教程/LATAlert/Example$ pod update --no-repo-update Later@localhost:~/Desktop/私有库建立教程/LATAlert$ pod repo add LATSpecs https://git.oschina.net/KKLater/LATPodspecs.git Later@localhost:~/Desktop/私有库建立教程/LATAlert$ pod lib lint Later@localhost:~/Desktop/私有库建立教程/LATAlert$ pod lib lint --verbose Later@localhost:~/Desktop/私有库建立教程/LATAlert$ pod repo push LATSpecs LATAlert.podspec Later@localhost:~/Desktop/私有库建立教程/LATAlert$ pod repo push LATSpecs LATAlert.podspec --verbose
//忽略警告
Later@localhost:~/Desktop/私有库建立教程/LATAlert$ pod lib lint
--allow-warningsLater@localhost:~/Desktop/私有库建立教程/LATAlert$ pod repo push LATSpecs LATAlert.podspec
Later@localhost:~$ pod repo remove LATSpecs
下面咱们经过一个例子来具体讲解整个步骤流程。
例子里面,咱们建立一个私有库LATAlert,导入LATAlert私有库的项目,能够调用私有库的方法来执行弹出一个Alert显示信息!服务器
先建立个文件夹来放置 这个例子的文件夹名字:私有库建立教程
Later@localhost:~$ cd /Users/Later/Desktop/私有库建立教程 Later@localhost:~/Desktop/私有库建立教程$ pod lib create LATAlert
注意:cocoapods要升级到最新版本。 我以前电脑是旧版本,是不会出现下面的界面的。 至于旧版本怎么设置下面这些属性我的没研究,有兴趣的能够本身试试。框架
终端获得如下界面:
这里会询问几个问题(答案根据实际状况设置),分别是:
一、语言选择
—— 教程选择Objc,若是要作Swift私有库,请选择输入Swift
二、是否是须要一个demo项目工程
—— 教程选择Yes,须要建立一个demo工程,建议建立一个demo工程
三、测试框架使用哪个
—— 教程选择None
四、是否是须要作基本的测试
—— 教程选择Yes
五、类前缀是什么
—— 教程输入LATtcp
若是出现上面的界面,说明,私有库工程建立成功了。ide
Later@localhost:~$ cd /Users/Later/Desktop/私有库建立教程/LATAlert/Example Later@localhost:~/Desktop/私有库建立教程/LATAlert/Example$ pod install --no-repo-update
终端界面以下:工具
双击LATAlert.xcworkspace运行项目Example工程,验证工程的正确性。
将源码文件复制到文件夹路径:LATAlert/LATAlert/Classes下。
资源文件放到Assets下。
注:1.若是尚未源码,则能够在Example下直接建立源码文件,实际测试经过后,再按照下面的方式来添加源码文件。2.方便起见这里直接将以前使用的源码文件拷贝过来,其余根据实际状况,看官自行添加。3.文件路径并非绝对的,可是建议按指定路径存放,便于总体的后期维护更新
双击打开LATAlert.podspec文件,此处我设置了默认Atom打开,看官自行配置,可是要注意编辑内容必定要教程同样。
咱们能够把没有用的注释删掉。具体经常使用的配置以下:
# # Be sure to run `pod lib lint LATAlert.podspec' to ensure this is a # valid spec before submitting. # # Any lines starting with a # are optional, but their use is encouraged # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html # Pod::Spec.new do |s| #库名 s.name = 'LATAlert' #库版本 s.version = '0.0.1' #库简短描述 s.summary = 'A short description of LATAlert.' #库详细描述 s.description = <<-DESC TODO: Add long description of the pod here. DESC #库介绍主页地址 s.homepage = 'https://github.com/<GITHUB_USERNAME>/LATAlert' #库开源许可 s.license = { :type => 'MIT', :file => 'LICENSE' } #做者信息 s.author = { 'Later' => 'lshxin89@126.com' } #源码git地址 s.source = { :git => 'https://github.com/<GITHUB_USERNAME>/LATAlert.git', :tag => s.version.to_s } #库依赖系统版本 s.ios.deployment_target = '8.0' #源码文件配置 s.source_files = 'LATAlert/Classes/**/*' #资源文件配置 s.resource_bundles = { 'LATAlert' => ['LATAlert/Assets/*.png'] } #源码头文件配置 s.public_header_files = 'Pod/Classes/**/*.h' #系统框架依赖 s.frameworks = 'UIKit', 'MapKit' #第三方框架依赖 s.dependency 'AFNetworking', '~> 2.3' end
清理掉不须要的配置项以后,总体以下:
Pod::Spec.new do |s| #库名 s.name = 'LATAlert' #库版本 s.version = '0.0.1' #库简短描述 s.summary = 'A short description of LATAlert.' #库详细描述 s.description = <<-DESC TODO: Add long description of the pod here. DESC #库介绍主页地址 s.homepage = 'https://github.com/<GITHUB_USERNAME>/LATAlert' #库开源许可 s.license = { :type => 'MIT', :file => 'LICENSE' } #做者信息 s.author = { 'Later' => 'lshxin89@126.com' } #源码git地址 s.source = { :git => 'https://github.com/<GITHUB_USERNAME>/LATAlert.git', :tag => s.version.to_s } #库依赖系统版本 s.ios.deployment_target = '8.0' #源码文件配置 s.source_files = 'LATAlert/Classes/**/*' #源码头文件配置 s.public_header_files = 'LATAlert/Classes/*.h' #系统框架依赖 s.frameworks = 'UIKit' end
细心的看官注意到,这里咱们使用的homepage和source并不完整下面就须要咱们建立一个git私有库,用于项目工程的存放,获取咱们所须要的地址。
点击建立,咱们的私有库就建立完成了,复制咱们的私有库地址,也就是咱们的.podspec文件里面source所须要的地址了。
source有了,可是咱们的homepage怎么办呢?若是有能够访问的高大上的介绍网页页面,建议使用其网址。
至此,咱们的配置文件就结束了。此时细心的看客又说了,咱们建立了git私有库,可是尚未添加文件啊?
六、再次进入咱们的Example文件,执行pod更新指令,安装本地库源码
Later@localhost:~/Desktop/私有库建立教程/LATAlert/Example$ pod update --no-repo-update
终端截图以下:
此时进入咱们的Example文件夹,双击LATAlert.xcworkspace打开看看:
咱们的源码已经在里面了。
这时,能够填写咱们的样例代码来进行测试喽。
找到咱们的样例文件LATViewController.m,引入头文件LATAlert.h,填写代码,点击屏幕时执行弹出Alert提示框,具体代码以下:
// // LATViewController.m // LATAlert // // Created by Later on 10/14/2016. // Copyright (c) 2016 Later. All rights reserved. // #import "LATViewController.h" #import "LATAlert.h" @interface LATViewController () @end @implementation LATViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [LATAlert showAlertWithTitle:@"测试" message:@"这时测试信息" OkBlock:^{ NSLog(@"点击了确认"); }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
运行项目测试:
alert信息弹出了,说明,咱们的本地运行例程是正常的。下面就须要咱们把项目发布到git,并添加到pod了。
为了保证项目的正确性,尤为是pod配置文件的正确性,在正式提交前,咱们须要执行如下本地验证。在本地验证正常的状况下,再上传发布仍是比较稳妥的。
终端进入咱们的项目文件路径:
Later@localhost:~/Desktop/私有库建立教程/LATAlert/Example$ cd /Users/Later/Desktop/私有库建立教程/LATAlert
若是如今终端正处于Example文件路径下,也能够执行
Later@localhost:~/Desktop/私有库建立教程/LATAlert/Example$ cd ..
退回到上层文件夹,也就是咱们的项目文件路径了。
执行pod本地验证指令:
Later@localhost:~/Desktop/私有库建立教程/LATAlert$ pod lib lint
或者忽略警告的指令:
Later@localhost:~/Desktop/私有库建立教程/LATAlert$ pod lib lint --allow--warning
界面显示:
若是经验丰富,大概一看便知这里的警告是告诉咱们这个summary简介不是颇有内涵。此处咱们改一下咱们的podspec文件内部的简介和描述,消除下警告。修改完的podspec文件以下。
# # Be sure to run `pod lib lint LATAlert.podspec' to ensure this is a # valid spec before submitting. # # Any lines starting with a # are optional, but their use is encouraged # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html # Pod::Spec.new do |s| #库名 s.name = 'LATAlert' #库版本 s.version = '0.0.1' #库简短描述 s.summary = 'LATAlert pod Use.' #库详细描述 s.description = <<-DESC TODO: LATAlert pod Use. DESC #库介绍主页地址 s.homepage = 'http://mobile.fblife.com' #库开源许可 s.license = { :type => 'MIT', :file => 'LICENSE' } #做者信息 s.author = { 'Later' => 'lshxin89@126.com' } #源码git地址 s.source = { :git => 'https://git.oschina.net/KKLater/LATAlert.git', :tag => s.version.to_s } #库依赖系统版本 s.ios.deployment_target = '8.0' #源码文件配置 s.source_files = 'LATAlert/Classes/**/*' #源码头文件配置 s.public_header_files = 'LATAlert/Classes/*.h' #系统框架依赖 s.frameworks = 'UIKit' end
鉴因而初学者,仍是建议掌握下查看具体缘由的指令比较靠谱。具体指令也很简单,在执行本地验证的指令后面添加上--verbose在执行下就能够了。
Later@localhost:~/Desktop/私有库建立教程/LATAlert$ pod lib lint --verbose
咱们再次执行下验证,查看结果,BUILD SUCCEEDD,本地验证成功:
至此,咱们的源码已经导入、样例工程已经验证执行、podspec配置文件本地已经验证,那么咱们是否是就能够直接在pod里面使用了呢?答案是确定的,仍是不行!目前只是处于本地状态,并无发布,因此仍是不能使用的。
在项目工程文件下执行git相关指令,并添加tag0.0.1,发布到git。
Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git remote add origin https://git.oschina.net/KKLater/LATAlert.git Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git add . Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git commit -a -m "0.0.1" Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git pull origin master Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git push origin master Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git tag 0.0.1 Later@localhost:~/Desktop/私有库建立教程/LATAlert$ git push origin 0.0.1
相关指令执行结束后,此时咱们再去看咱们的git项目:
对于开源框架,podspec文件实在cocoapod的开源管理spec项目上面的,见下图:
在这里的Specs文件加内,咱们能看到咱们熟悉的 AFNetworking
可是咱们建立的是私有库,因此咱们须要建立本身的Specs管理库。
例如咱们要建立的是LATSpecs,首先须要再建立一个git私有库,用于管理咱们的LATSpecs。
建立以后获取到git地址:https://git.oschina.net/KKLater/LATPodspecs.git
在终端执行Specs建立指令:
Later@localhost:~/Desktop/私有库建立教程/LATAlert$ pod repo add LATSpecs https://git.oschina.net/KKLater/LATPodspecs.git
执行以后的结果是:
看到这个,咱们能够愉快的发布了。执行发布命令,直接发布好了。
Later@localhost:~/Desktop/私有库建立教程/LATAlert$ pod repo push LATSpecs LATAlert.podspec
若是有问题 能够试试忽略警告
Later@localhost:~/Desktop/私有库建立教程/LATAlert$ pod repo push LATSpecs LATAlert.podspec --allow--warnings
发布成功以后,咱们来看一下咱们的LATSpecs的git项目:
查看咱们本地的Specs库:
直接Findle ->右键 -> 前往文件夹 -> 输入:~/.cocoapods/repos ->点击前往
至此,咱们的私有库建立发布结束。可是咱们注意到,LATSpecs的README.md文件是空的,为了后期的维护更新,以及团队小伙伴的使用方便,建议完备一下信息。
完备以后的信息以下:
终端执行一下进入咱们的私有库管理Specs,git更新提交下:
Later@localhost:~$ cd /Users/Later/.cocoapods/repos/LATSpecs Later@localhost:~/.cocoapods/repos/LATSpecs$ git add . Later@localhost:~/.cocoapods/repos/LATSpecs$ git commit -a -m "Add LATAlert" Later@localhost:~/.cocoapods/repos/LATSpecs$ git pull origin master Later@localhost:~/.cocoapods/repos/LATSpecs$ git push origin master
命令行执行结束以后,咱们再看一下咱们的git:
有没有高大上呢?
既然已经提交发布,那下面咱们新建一个CocoaPods管理的项目,来验证一下咱们的库吧。
新建PodTest项目,并建立Podfile文件,安装CocoaPods工程。
Podfile文件内的代码以下:
platform :ios,'8.0' target 'PodTest' do pod 'LATAlert',:git => 'https://git.oschina.net/KKLater/LATAlert.git' end
注意:podfile文件里要加上
source 'https://github.com/CocoaPods/Specs.git'
source 'http://112.124.41.46/tuchaoprivatecommon/xgtcprivatepodsrepo.git'
若是你不配置系统的索引库 会找不到其余的库 只能找到你本身建立的仓库
最近一个命令 pod install
Nice 完成了
终端进入咱们的测试工程根目录,并执行pod安装指令:
Later@localhost:~$ cd /Users/Later/Desktop/私有库建立教程/PodTest Later@localhost:~/Desktop/私有库建立教程/PodTest$ pod install --no-repo-update
终端界面以下:
咱们从新打开测试项目:
在ViewController.m文件导入文件,并按照Example的样例书写代码验证。代码以下:
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [LATAlert showAlertWithTitle:@"测试" message:@"这时测试信息" OkBlock:^{ NSLog(@"点击了确认"); }]; }
不一样的是,这里引入头文件时,咱们使用的是:#import <LATAlert/LATAlert.h>而不是Example样例工程里面的引入方式:#import "LATAlert.h"。
运行PodTest项目,点击屏幕,是否是也弹出Alert提示了呢?
至此,咱们的私有库发布结束。具体更详细的信息,建议各位看客多多参考CocoaPods官网,会有更不同的体验。英语很差的,体验会更加深入哟!
至于更新版本的话
localhost:xgoalibrary kfj$ git add . //新增的文件 加入仓库
localhost:xgoalibrary kfj$ git commit -a -m "0.1.2" "0.1.2" -- tag 号 // 须要提交的文件上传确认
localhost:xgoalibrary kfj$ git pull origin master //下啦最新资源
localhost:xgoalibrary kfj$ git push origin master //上传本地最新代码
localhost:xgoalibrary kfj$ git tag 0.1.2 //打tag
localhost:xgoalibrary kfj$ git push --tags
localhost:xgoalibrary kfj$ pod lib lint --allow-warnings //验证本地库是否正确 lib 换成 spec 的 话 就是 就是验证远程服务器的 库 是否正确
localhost:xgoalibrary kfj$ pod repo push XGOALibrary XGOALibrary.podspec --allow-warnings
命令行指令:
history 查看本身用过的历史指令
pod repo list 查看本地repo私有库资源信息
open ~/.cocoapods 打开本地私有库资源的位置