安装使用,涉及一些命令总结,可跳过
--------复制粘贴专用区Begin
1.CocoaPods 安装
本不想写,但方便我部署新机器安装CocoaPods的时候顺手能拷贝。
1.升级ruby包管理工具gem
sudo gem update --system
2.修改gem源镜像地址
先查看自己电脑的默认的地址,理论上应该是https://rubygems.org/
gem sources -l
删除默认
gem sources --remove https://rubygems.org/
添加https://gems.ruby-china.org/作为源地址
gem sources -a https://gems.ruby-china.org/
3.安装命令
执行:
sudo gem install cocoapods -n /usr/local/bin 或者
sudo gem install -n /usr/local/bin cocoapods
避免出现
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
安装过程中出现类似/usr/local/bin找不到的报错,配置一下环境变量
vim ~/.bash_profile
export PATH=$PATH:/usr/local/bin
source ~/.bash_profile
出现
can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/ffi-1.12.2 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.12.2/gem_make.out
这样的报错
问题原因以及解决方案:
For Xcode 11 on macOS 10.14, this can happen even after installing Xcode and installing command-line tools and accepting the license.
The issue is that Xcode 11 ships the macOS 10.15 SDK which includes headers for ruby2.6, but not for macOS 10.14's ruby2.3. You can verify that this is your problem by
running:
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
which on macOS 10.14 with Xcode 11 prints the non-existent path:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0
However, Xcode 11 installs a macOS 10.14 SDK within /Library/Developer/CommandLineTools/SDKs/MacOS10.14.sdk. It isn't necessary to pollute the system directories by installing the old header files as suggested in other answers. Instead, by selecting that SDK, the appropriate ruby2.3 headers will be found:
sudo xcode-select --switch /Library/Developer/CommandLineTools
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
This should now correctly print:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0
Likewise, gem install should work while that SDK is selected.
To switch back to the current Xcode SDK, use:
sudo xcode-select --switch /Applications/Xcode.app
...赶紧升级10.15就OJBK.
2.Git 一些命令
1.查询远程仓库具体地址
git remote -v
2.打tag相关的命令
查看tag:
git tag
生成tag:
git tag 0.0.1 指定版本号做tag名字
git tag select_commit_tag 6b359c4 拉取某个commit指定名字作为tag
push tag到远程git仓库:
git push --tags push所有本地tag
git push origin 0.0.1 push版本号类型tag
git push origin select_commit_tag push名字类型tag
删除tag:
git tag -d 0.0.1 本地删除版本号类型tag
git tag -d select_commit_tag 本地删除名字类型tag
git push origin :0.0.1 删除远程仓库tag
git push origin :select_commit_tag
3.CocoaPods添加私有仓库源
CocoaPods默认有一个master的仓库源,存放所有第三方框架的描述文件podspec(CocoaPods管理第三方框架不是存真正的代码,而是存每个框架对应的一个描述文件podspec,具体机制自行搜索相关资料,此处不再多赘述)
如果想要实现各自公司内部代码框架的组件化,就必须创建自己公司私有的的CocoaPods仓库源,把所有的podspec托管在自己公司的git仓库。
添加方法:
假设私有仓库名字:onePrivateRepo
假设私有仓库地址:https://yourcompany.com/onePrivateRepo/onePrivateRepo.git
执行以下命令:
pod repo add onePrivateRepo https://yourcompany.com/onePrivateRepo/onePrivateRepo.git
查看所有仓库
执行命令:
pod repo list
打印结果:
onePrivateRepo
- Type: git (master)
- URL: https://yourcompany.com/onePrivateRepo/onePrivateRepo.git
- Path: /Users/hanxiaoqing/.cocoapods/repos/onePrivateRepo
master
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/hanxiaoqing/.cocoapods/repos/master
2 repos
Path是本地缓存地址,避免每一次都从仓库拉取所有的podspec,也就解释为什么安装完成cocoapods后,执行pod setup会很慢很慢,这个过程就是从master https://github.com/CocoaPods/Specs.git同步到本地的下载过程。
想了解更深的CocoaPods原理机制,参考 iOS系列译文:深入理解 CocoaPods
--------复制粘贴专用区End
玩转并深入理解CocoaPods需要补充的一些知识点
1.组件包含c++代码产生问题
先了解Xcode编译c++以及设置的一些tips:
Apple 为什么在 Mavericks 里把 C++ 标准库从 libstdc++ 改成 libc++
实施CocoaPods集成过程中,SDK带有c++源代码,无法通过pod lint编译验证,提交podspec失败解决
后续补充
2.Xcconfig
Xcconfig能够配置xcode buildsetting的编译选项,还可以在不同mode下采用不同的配置,有一定的复用性。
使用实例可以参考jspahrsummers/xcconfigs,这个人把所有用法整理到github仓库,例子很清晰。
其他参考:
Xcode使用xcconfig文件配置环境
The Unofficial Guide to xcconfig files
3.Header Search Paths
正确认识Header Search Paths,User Header Search Paths,Always Search User Paths,以及
include <>与include " ",参考下面文章
Objective-C 中的 import 和 Search Paths(超级详细首选)
Xcode增加头文件搜索路径的方法
Xcode Search Paths选项配置
4.CocoaPods与工程配置
静态库本质,自定义静态库包含分类找不到方法的报错经典问题解析,CocoaPods是怎么引用静态库到主工程,参考细聊 Cocoapods 与 Xcode 工程配置
5.Umbrella Header
iOS - Umbrella Header在framework中的应用
CocoaPods实用技巧以及常见问题解决收集
1.Xcode BuildSetting选项的继承问题
有些时候使用CocoaPods依赖某个库,写好podfile,pod install产生警告:
[!] The xxx[Release] target overrides the HEADER_SEARCH_PATHS build setting defined in
Pods/Target Support Files/Pods-xxx/Pods-xxx.release.xcconfig'.
This can lead to problems with the CocoaPods installation - Use the$(inherited)` flag, or
- Remove the build settings from the target.
[!] The xxx[Release] target overrides the LIBRARY_SEARCH_PATHS build setting defined in
Pods/Target Support Files/Pods-xxx/Pods-xxx.release.xcconfig'.
This can lead to problems with the CocoaPods installation - Use the$(inherited)` flag, or
- Remove the build settings from the target.
打开workspace编译,还是报错找不到依赖库,这很可能是与原主工程BuildSetting的某些选项产生了
冲突,这就涉及到了BuildSetting继承问题, 要用$(inherited)搞定,具体参考pod install出现Use the xxxx flag警告
2.CocoaPods的一些hook钩子
pre install hook, post install hook,参考基于 CocoaPods 进行 iOS 开发,里面还有操作pbxproj文件修改build settings的实例。
prepare_command的使用:谈谈CocoaPods组件二进制化方案
3.自动生成Framework库工程以及关联Test工程
借助CocoaPods Packager,可以通过自动生成Framework库工程以及关联Test工程,并跟CocoaPods
无缝结合,进行组件化管理,参考iOS 利用工具制作Framework库
4.清理缓存
1.pod install后,会在~/Library/Caches/CocoaPods目录缓存一份所有install过的库,在使用CocoaPods过程中,有些时候使用出现死活都摸不到头脑的问题,比方说podfile明明写了依赖的库,CocoaPods也没问题,执行pod install也没出问题,就是工程build不成功,还是找不到执行的库,那就试试清缓存的命令:
pod cache clean --all 其实等价于 rm -rf ~/Library/Caches/CocoaPods
2.pod install后,会在原来的xcode工程里面加很多东西,为CocoaPods准备舞台,然后我们都是打开xcworkspace去build,但有的时候想要去除CocoaPods对原来的工程的修改,可以使用:
在目标工程的xcworkspace文件同级目录,也就是你执行pod install的目录,执行:
pod deintegrate
通过观察输出打印:
Deleted 1 'Copy Pods Resources' build phases.
Deleted 1 'Check Pods Manifest.lock' build phases.
- libPods-sdkTest.a
- Pods-sdkTest.debug.xcconfig
- Pods-sdkTest.release.xcconfig
Deleting Pod file references from project
- libPods-sdkTest.a
Deleted 1 empty `Pods` groups from project.
Removing `Pods` directory.
Project has been deintegrated. No traces of CocoaPods left in project.
明白了。。。CocoaPods对原工程搞了很多事情。。。
3.终极大清理
清除安装库缓存 + 还原原工程 + 去除xcode缓存
pod cache clean --all
pod deintegrate
rm -rf ~/Library/Developer/Xcode/DerivedData/*
这是大招轻易不用的。。。。
5.使用规范标准总结
1、第一次获取pod库时,应使用pod install。
2、pod outdated和pod update都会更新spec仓库,但是pod install不会,所以对于经常使用的pod库,建议经常pod outdated关注更新情况。因此,需要更新依赖库时,先使用pod outdated查看有哪些库有更新,再使用pod update PODNAME有目的的更新指定库
3、提交代码时,请注意一定同时提交Podfile.lock文件,以便其他人能同步到与你相同的pod库版本。
4、同步其他团队成员的修改时,请使用pod install。
总结
重点关注CocoaPods实用技巧以及常见问题解决收集,其他都是扯淡。。。。
下一篇会讲利用我研究,总结的CocoaPods的一些API,写一些ruby脚本,扩充CocoaPods功能。。