标签:
platform:ios,7.0
pod ‘SDWebImage‘
pod ‘MBProgressHUD‘
pod ‘AFNetworking‘
pod ‘MFSideMenu‘
#pod ‘ZBarSDK‘, ‘~> 1.3.1‘
最新版本-后面不能添加版本号;
指定 SDK 版本
CocoaPods 中,有几种设置 SDK 版本的方法。如:
‘>= 2.4.X‘ 会根据您本地的 CocoaPods 源列表,导入不低于 2.4.X 版本的 SDK。
‘~> 2.4.X‘ 会根据您本地的 CocoaPods 源列表,介于 2.4.X~2.5.0 之前版本的 SDK。
我们建议您锁定版本,便于团队开发。如,指定 2.4.X 版本。
$ sudo gem install cocoapods
1.During this process RubyGems might ask you if you want to overwrite the rake
executable. This warning is raised because the rake
gem will be updated as part of this process. Simply confirm by typing y
.
在此过程中的RubyGems可能会问你,如果你要覆盖耙
可执行文件。这个警告是因为引发了耙
宝石将被更新,这个过程的一部分。只需键入确认ÿ
。
第一次用sudo的时候会有一个警告:
WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.
To proceed, enter your password, or type Ctrl-C to abort.
警告:错误的使用sudo工具会导致数据丢失,或者缺失重要的系统文件。请复核你的键入,当使用sudo。 键入 man sudo 得到更多信息。
2.If you do not want to grant RubyGems admin privileges for this process, you can tell RubyGems to install into your user directory by passing either the --user-install
flag to gem install
or by configuring the RubyGems environment. The latter is in our opinion the best solution. To do this, create or edit the .profile
file in your home directory and add or amend it to include these lines:
如果你不希望授予RubyGems的管理员权限这个过程中,你可以告诉RubyGems的传递无论是安装到你的用户目录--user-install
标志gem install
或配置RubyGems的环境。后者是我们认为最好的解决方案。要做到这一点,创建或编辑 .profile
文件在你的home目录下,并添加或修改它包含这些行:
博客地址:
http://www.easymorse.com/index.php/archives/672
-------------------------------------------------------------------------------------------------------------------------
一.检查是否安装了必要得工具。
如果安装了Xcode,那么git就已经安装了,可以确认一下:
1.ruby -v:检查ruby有没有啊,亲!
zhuxinmingdeMacBook-Pro:~ simon$
ruby -v
ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]
2.git —version 确认安装了git version 1.8.3.4
zhuxinmingdeMacBook-Pro:~ simon$git —-version
git version 2.5.4 (Apple Git-61)
Unknown option: -version
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
3.检查是否 安装Xcode的Command line工具,如果您的xcode未安装Command Line Tools将会报错
二.更新Ruby环境下的gem
RubyGems(简称 gems)是一个用于对 Rails 组件进行打包的 Ruby 打包系统。 它提供一个分发 Ruby 程序和库的标准格式,还提供一个管理程序包安装的工具。(可以到这个网址http://www.
ruby-lang.org/查看ruby版本是否最新。)
1.gem update+空格+--system
XinMinghudeiMac:~ Simon$ gem update --system
(1)如果更新失败:
Updating rubygems-update
Fetching: rubygems-update- 2.5.1.gem (100%)—表示有最新的gems环境2.4.5版本。
ERROR: While executing gem ... (Gem::FilePermissionError)
You don‘t have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
表示没有写入权限:
如果出现没有权限,多加一个sudo。
sudo gem update+空格+—system
(2)如果已经是最新的版本:
则回复为Latest version currently installed. Aborting.
------
(3)如果需要更新且更新成功:
Updating rubygems-update
Fetching: rubygems-update-2.5.1.gem (100%)Fetching: rubygems-update-2.5.1.gem
Successfully installed rubygems-update-2.5.1
Parsing documentation for rubygems-update-2.5.1
Installing ri documentation for rubygems-update-2.5.1
Installing darkfish documentation for rubygems-update-2.5.1
Parsing documentation for rubygems-update-2.5.1
Installing RubyGems 2.5.1
RubyGems 2.5.1 installed
------------------------------------------------------------------------------
RubyGems installed the following executables(可执行文件):
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/gem
Ruby Interactive (ri) documentation was installed. ri is kind of like man
pages for ruby libraries. You may access it like this:
ri Classname
ri Classname.class_method
ri Classname#instance_method
If you do not wish to install this documentation in the future, use the
--no-document flag, or set it as the default in your ~/.gemrc file. See
‘gem help env‘ for details.
RubyGems system software updated
zhuxinmingdeMacBook-Pro:~ simon$
--------------------------------------------------------------------------------
1.如果执行gem的时候返回出错,
(1)返回出错1:返回如下:
ERROR: Could not find a valid gem ‘cocoapods‘ (>= 0), here is why:
原因:墙拦截了。
(2)返回出错2:返回如下:
ERROR: While executing gem ... (Gem::RemoteFetcher::UnknownHostError)
原因:墙拦截了。
(3) 返回出错3:返回如下:(不支持https)
-------------------------------
解决:我们可以通过替换rubygems镜像为淘宝的Ruby镜像,在终端输入如下命令将Ruby镜像替换为淘宝的;
$ gem sources --add https://ruby.taobao.org/ - 再添加;
//或者用淘宝的:
----------------------------------------------------
2.检查:gem镜像环境:
$ gem sources
zhuxinmingdeMacBook-Pro:MusicBa simon$ gem sources
*** CURRENT SOURCES ***
如果输出是以下这样,说明还是原来的rubygems;
-----------------------------------------
三.安装CocoaPods
安装CocoaPods之前,先确保本地有Ruby环境,因为CocoaPods运行于Ruby之上,默认情况下,Mac是自带了Ruby环境的,可以通过命令行ruby -v查看当前Ruby的版本。接下来我们就可以通过如下命令安装CocoaPods了。
$ sudo gem install cocoapods
----------------------------------------------------
如果是第一次使用sudo:会出现警告;
WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.
警告:sudo命令的不当使用可能会导致数据丢失
或删除重要的系统文件
不用管,没关系的。
To proceed, enter your password, or type Ctrl-C to abort.
Fetching: i18n-0.6.9.gem (100%)
Successfully installed i18n-0.6.9
Fetching: multi_json-1.8.2.gem (100%)
Successfully installed multi_json-1.8.2
Fetching: activesupport-3.2.16.gem (100%)
Successfully installed activesupport-3.2.16
Fetching: nap-0.6.0.gem (100%)
Successfully installed nap-0.6.0
Fetching: json_pure-1.8.1.gem (100%)
Successfully installed json_pure-1.8.1
Fetching: fuzzy_match-2.0.4.gem (100%)
Successfully installed fuzzy_match-2.0.4
Fetching: cocoapods-core-0.29.0.gem (100%)
Successfully installed cocoapods-core-0.29.0
Fetching: claide-0.4.0.gem (100%)
Successfully installed claide-0.4.0
Fetching: cocoapods-downloader-0.3.0.gem (100%)
Successfully installed cocoapods-downloader-0.3.0
Fetching: rake-10.1.1.gem (100%)
rake‘s executable "rake" conflicts with /usr/bin/
ERROR: Error installing cocoapods:
"rake" from rake conflicts with /usr/bin/rake
如果出现rake‘s executable "rake" conflicts with /usr/bin/rake
Overwrite the executable? [yN] y
则y来重写冲突。
(2)返回出错二:
fatal: The remote end hung up unexpectedly
检查是否安装成功cocoapods:
$ pod repo list
如果是以下则表示已安装成功:
(3) 返回错误三:
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
解决办法
sudo gem install -n /usr/local/bin cocoapods
------------------
2.如果返回成功:
查看当前cocoapods的版本:gem which cocoapods
ZhuXinMingdeMac-mini:~ zhuxinming$ gem which cocoapods
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.39.0/lib/cocoapods.rb
-------------------------------
(四)更新cocoaPods
如果需要更新CocoaPods到最新版本输入如下命令:
1、如果想为每个第三方库生成文档,那运行
brew install appledoc 这步是可选的。
安装完成后提示:
错误:遇到 Executable pull--在安装了cocoapods,系统又更新到最新版本os x的时候,遇到错误。
echodeiMac:~ echo$ pod setup
Setting up CocoaPods master repo
[!] Pod::Executable pull
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use ‘git add/rm <file>‘
as appropriate to mark resolution, or use ‘git commit -a’.
解决办法 可以使用 pod repo remove master; pod setup
echodeiMac:~ echo$ pod repo remove master
Removing spec repo `master`
echodeiMac:~ echo$
pod setupSetting up CocoaPods master repo
Setup completed (read-only access)
解决方法:
$ pod repo remove master
$ pod setup
如果还不行则重新安装:
pod$ sudo rm -rf ~/.cocoapods/
$ pod setup
五:搜索第三方库
如果你需要什么库,可以用pod来搜索,比如搜索JSONKit这个库: pod search JSONKit
可能会出现:Setting up CocoaPods master repo
六.安装第三方库:初始化,进入app目录,新建一个名为Podfile的文件.
检测完毕后我们来到工程CocoaPodsTest的目录下,新建一个名为Podfile的文件(这里通过命令行创建)
- $ vim Podfile
这个Podfile文件的作用是配置依赖库信息,就是告诉CocoaPods去下载和管理哪些依赖库,文件创建好以后,打开文件并加入如下内容。(vim打开文件后按i进入插入模式,编辑完成后按esc退出编辑模式,接着输入:wq保存并退出文件)
cd+空格+app拖进来的目录
appletekiiMac:~ apple$ cd /Users/apple/Desktop/DingXi //初始化,进入app目录
appletekiiMac:DingXi apple$ touch Podfile //新建一个名为Podfile的文件
appletekiiMac:DingXi apple$ open Podfile //打开文件————换电脑后,这个重新打开,写加载的开源
在打开的文件输入:
platform:ios,6.1
pod ‘SDWebImage’, ‘~> 3.7.1‘
pod ‘ZBarSDK‘, ‘~> 1.3.1‘
pod ‘ZXing‘, ‘~> 2.3’ //不要加这个,配置有问题,这个配置太繁琐了;
pod ‘ZXingObjC‘, ‘~> 3.0.3‘
pod ‘UIActivityIndicator-for-SDWebImage‘, ‘~> 1.2‘
pod ‘SDWebImage-ProgressView‘, ‘~> 0.4.0‘
pod‘ASIHTTPRequest‘,‘~> 1.8.2‘
pod‘MBProgressHUD‘,‘~> 0.8’
如果没有输入正确,或许有换行符。会报错。
unterminated string meets end of file
执行命令:pod install
看仔细过程: pod install –verbose
其中
Pods目录是一个xcode项目,里面包含所有在Podfile中声明的第三方库代码;
App.xcworkspace 为xcode的工作空间文件,以后用这个文件来打开项目;
Podfile.lock 文件记录所有已安装的代码库的描述(不可更改),文件如下:
注意点:
- 使用CocoaPods生成的.xcworkspace 文件来打开工程,而不是以前的 .xcodeproj 文件。
- 每次更改了Podfile文件,cd+空格+app拖进来的目录,你需要重新执行一次 Pod install命令。
- 运行时项目名称选择你自己的项目名称而不是Pods
一.启动程序导致的报错:
diff: /../Podfile.lock: No such file or directory diff: /Manifest.lock: No such file or directory error: The sandbox is not in sync with the Podfile.lock. Run ‘pod install‘ or update your CocoaPods installation.
或者出现这种错误:
/Users/zhuxinming/Library/Developer/Xcode/DerivedData/NBEntertainment-clgpubjdvgopgzbhnrovxswhlixt/Build/Intermediates/NBEntertainment.build/Debug-iphonesimulator/NBEntertainment.build/Script-8487E21DF0D3490EBAC94484.sh: line 2: /Users/zhuxinming/Desktop/海曙文化协会/Pods/Pods-resources.sh: Permission denied
pod 没有权限。(可能是换了电脑导致)--
解决办法:进入到工程目录pod install 重新安装一下。
————————————————————————————————
——————————————————————————
zhuxinmingdeMacBook-Pro:ShiChunTang simon$ pod install
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.34.4/lib/cocoapods/user_interface/error_report.rb:13:in `report‘: incompatible character encodings: UTF-8 and ASCII-8BIT (Encoding::CompatibilityError)不兼容的字符编码:utf - 8和ASCII-8BIT(编码::CompatibilityError)
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.34.4/lib/cocoapods/command.rb:63:in `report_error‘
from /Library/Ruby/Gems/2.0.0/gems/claide-0.7.0/lib/claide/command.rb:300:in `handle_exception‘
from /Library/Ruby/Gems/2.0.0/gems/claide-0.7.0/lib/claide/command.rb:274:in `rescue in run‘
from /Library/Ruby/Gems/2.0.0/gems/claide-0.7.0/lib/claide/command.rb:264:in `run‘
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.34.4/lib/cocoapods/command.rb:50:in `run‘
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.34.4/bin/pod:33:in `<top (required)>‘
from /usr/bin/pod:23:in `load‘
from /usr/bin/pod:23:in `<main>‘
------------------------------------------------------------------------
pod install
Ignoring xcodeproj-0.16.1 because its extensions are not built. Try: gem pristine xcodeproj-0.16.1
Ignoring xcodeproj-0.17.0 because its extensions are not built. Try: gem pristine xcodeproj-0.17.0
/Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require‘: cannot load such file -- xcodeproj/prebuilt/universal.x86_64-darwin14-2.0.0/xcodeproj_ext (LoadError)
扩展没有建立,尝试 gem pristine xcodeproj-0.16.1
运行这个也是这个结果。
ZhuXinMingdeMac-mini:baohuai_iPhone 2.4 zhuxinming$ pod repo remove master
Ignoring xcodeproj-0.16.1 because its extensions are not built. Try: gem pristine xcodeproj-0.16.1
-----------
问题1:
[!] CocoaPods was not able to update the `master` repo. If this is an unexpected issue and persists you can inspect it running `pod repo update --verbose`
清除CocoaPods缓存后重新pod setup,解决问题.
sudo rm -fr ~/.cocoapods/repos/master
pod setup
简单来说就是0.32之后的CocoaPods repo目录访问现在不需要root权限了,之前版本生成的目录权限在新版本下会有权限问题,所以需要删除重新生成一次。
--------------------
官方文档翻译:
The dependencies for your projects are specified in a single text file called a Podfile. CocoaPods will resolve dependencies between libraries, fetch the resulting source code, then link it together in an Xcode workspace to build your project.
指定项目的依赖关系在一个文本文件称为Podfile。CocoaPods将解决库之间的依赖关系,获取生成的源代码,然后联系在一起,一个Xcode工作区来构建您的项目。
CocoaPods is built with Ruby and it will be installable with the default Ruby available on OS X. You can use a Ruby Version manager, however we recommend that you use the standard Ruby available on OS X unless you know what you‘re doing.
Using the default Ruby install will require you to use sudo
when installing gems. (This is only an issue for the duration of the gem installation, though.)
CocoaPods构建Ruby和它将与默认安装Ruby可以在OS X经理可以使用Ruby版本,但是我们建议你使用标准的Ruby可以在OS X上,除非你知道你在做什么。
使用默认的Ruby安装需要你安装时使用sudo宝石。(这只是一个问题的时间gem安装。)
If you encounter any problems during installation, please visit this guide.
如果你在安装过程中遇到任何问题,请访问本指南。
If you do not want to grant RubyGems admin privileges for this process, you can tell RubyGems to install into your user directory by passing either the --user-install
flag to gem install
or by configuring the RubyGems environment. The latter is in our opinion the best solution. To do this, create or edit the .profile
file in your home directory and add or amend it to include these lines:
if你不想RubyGems admin特权授予这个过程,你可以告诉RubyGems安装到您的用户目录通过——user-install国旗gem安装或配置RubyGems的环境。后者是我们认为最好的解决办法。为此,创建或编辑。概要文件在您的主目录,添加或修改包括这些线:
Updating CocoaPods
To update CocoaPods you simply install the gem again 重新安装就行
$ [sudo] gem install cocoapods
Or for a pre-release version 或者一个预发布版本
$ [sudo] gem install cocoapods --pre
If you originally installed the cocoapods gem using sudo, you should use that command again.
Later on, when you‘re actively using CocoaPods by installing pods, you will be notified when new versions become available with a CocoaPods X.X.X is now available, please update message.
Using a CocoaPods Fork
There is a guide for using a version of CocoaPods to try new features that are in discussion or in implementation stage.
如果您最初安装了cocoapods gem使用sudo,您应该使用command again。
后来,当你积极使用CocoaPods通过安装pods,时会通知你新版本可用CocoaPods X.X.现在X是可用的,请更新消息。
使用CocoaPods Fork
有一个指南使用的一个版本CocoaPods尝试新功能讨论或实现阶段。
Using CocoaPods
Adding Pods to an Xcode project
Before you begin
- Check the Specs repository or cocoapods.org to make sure the libraries you would like to use are available.
- Install CocoaPods on your computer.
cocoa pod
标签:
原文地址:http://www.cnblogs.com/YU411524/p/5346027.html