CocoaPods 安装 使用

作者: 咖咖嘻 | 来源:发表于2015-11-28 21:40 被阅读47006次

1.开启 terminal

2.移除现有 Ruby 默认源

$ gem sources --remove https://rubygems.org/

3.使用新的源

$ gem sources -a https://ruby.taobao.org/

4.验证新源是否替换成功

$ gem sources -l

5.安装 CocoaPods

$ sudo gem install cocoapods

$ pod setup

备注:苹果系统升级 OS X EL Capitan 后安装改为:

$ sudo gem install -n /usr/local/bin cocoapods

$ pod setup

6.更新 gem

$ sudo gem update --system

7.新建工程,并在终端用 cd 指令到文件夹内

$ pod search 第三方

8.新建 Podfile 文件

$ touch Podfile

9.编辑 Podfile 文件,并写入要添加的第三方库

platform:ios, '8.0'

pod 'AFNetworking', '~> 2.3.1'<-------第三方

10.导入第三方库

$ pod install

$ pod install --verbose --no-repo-update

11.退出终端



可能遇到的错误提示及解决方法:


Error 1:

Error fetching http://ruby.taobao.org/:

bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)

解决方案:把安装流程中 $ gem sources -a http://ruby.taobao.org/ 

改为:$ gem sources -a https://ruby.taobao.org/


Error 2:

ERROR:  While executing gem ... (Errno::EPERM)

Operation not permitted - /usr/bin/pod

解决方案:苹果系统升级 OS X EL Capitan 后会出现的插件错误,将安装流程 5.安装 CocoaPods 的 sudo gem install cocoapods

改为 sudo gem install -n /usr/local/bin cocoapods


Error 3:

[!] Unable to satisfy the following requirements:

- `AFNetworking (~> 2.3.1)` required by `Podfile`

Specs satisfying the `AFNetworking (~> 2.3.1)` dependency were found, but they required a higher minimum deployment target.

解决方案:Podfile 文件 中   platform:ios, ‘8.0’  后边的 8.0 是平台版本号 ,一定要加上


Error4:

――――――――― MARKDOWN TEMPLATE ――――――――――

### Report

* What did you do?

* What did you expect to happen?

* What happened instead?

### Stack

```

CocoaPods : 0.29.0

Ruby : ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

RubyGems : 2.1.11

Host : Mac OS X 10.9.2 (13C64)

Xcode : 5.1 (5B130a)

Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib

Repositories : master - https://github.com/CocoaPods/Specs.git @ bd6736d07b16c98ab7a1dae04697cae002f25a9b

```

### Podfile

```ruby

platform :ios,'8.0'

pod 'MBProgressHUD', '~> 0.8'

```

### Error

```

Psych::SyntaxError - (/Users/MAXJ/.cocoapods/repos/master/CocoaPods-version.yml): mapping values are not allowed in this context at line 3 column 4

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:205:in `parse'

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:153:in `parse'

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:129:in `load'

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:299:in `block in load_file'

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:299:in `open'

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:299:in `load_file'

/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/sources_manager.rb:261:in `version_information'

/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/sources_manager.rb:222:in `repo_compatible?'

/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/sources_manager.rb:281:in `master_repo_functional?'

/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/command.rb:39:in `parse'

/Library/Ruby/Gems/2.0.0/gems/claide-0.4.0/lib/claide/command.rb:179:in `parse'

/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/command.rb:38:in `parse'

/Library/Ruby/Gems/2.0.0/gems/claide-0.4.0/lib/claide/command.rb:211:in `run'

/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/command.rb:51:in `run'

/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/bin/pod:24:in `'

/usr/bin/pod:23:in `load'

/usr/bin/pod:23:in `'

```

―――――――――― TEMPLATE END ――――――――――

[!] Oh no, an error occurred.

Search for existing github issues similar to yours:

https://github.com/CocoaPods/CocoaPods/search?q=%28%2FUsers%2FMAXJ%2F.cocoapods%2Frepos%2Fmaster%2FCocoaPods-version.yml%29%3A+mapping+values+are+not+allowed+in+this+context+at+line+3+column+4&type=Issues

If none exists, create a ticket, with the template displayed above, on:

https://github.com/CocoaPods/CocoaPods/issues/new

Don't forget to anonymize any private data!

解决方案:

$ sudo rm -rf ~/.cocoapods/repos/master

$ pod setup


相关文章

网友评论

  • 懂你的:一个问题的解决:
    输入完这一句代码后可能会出现一个错误
    ERROR: While executing gem ... (Gem::DependencyError)
    Unable to resolve dependencies: cocoapods requires cocoapods-core (= 0.33.1), claide (~> 0.6.1), cocoapods-downloader (~> 0.6.1), cocoapods-plugins (~> 0.2.0), cocoapods-try (~> 0.3.0), cocoapods-trunk (~> 0.1.1), nap (~> 0.7)

    解决方法:sudo gem update --system

    但是出现了另一个错误:

    ERROR: While executing gem ... (Errno::EPERM)
    Operation not permitted - /usr/bin/xcodeproj

    于是上网查找了一下 问了一些朋友,于是在一个朋友的帮助下 得到了答案,他给我一个连接上面是一个网友的总结。他是在Stackoverflow上找到的解决方法(在此推荐网友可以多去这个网站看看,上面有很多中外的大牛回答的问题,对工作很久的大牛都是知识的宝藏,更何况对于我们这些菜鸟而言呢)
    解决方法如下

    在终端中输入:sudo nvram boot-args="rootless=0"; sudo reboot
    然后你的电脑会重启
    之后再输入 sudo gem install cocoapods -V
    就可以了
    不放心的话输入
    pod --version
    0.37.2 //显示出版本就说明成功了
  • renchendong:很不错的文章
  • ugvibib:写的好写的好 :grin:
  • 请叫我何大大:大神好叼啊,不光写了方法,还写了注释,棒棒哒
  • 儒雅的减肥大哥:搞了这么久,终于弄好了,我爱你,有时间睡一觉!
  • 颜思齐:很有帮助,谢谢
  • aecf8d9c6b79:xudeMacBook-Pro:~ xu$ sudo gem install -n /usr/local/bin cocoapods
    ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
    SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://rubygems-china.oss-cn-hangzhou.aliyuncs.com/quick/Marshal.4.8/cocoapods-1.0.1.gemspec.rz)


    这是什么原因啊。求解求解
    Laughingg:@沐沐沐沐沐游 在 mac 10.11 开启了 rootless 权限, 导致不能对 /usr/bin 目录进行读写操作。

    关闭 rootless 权限就可,回到 10.11 之前的状态。 前提是要舍弃一点安全性。
  • 国强在线:Error3。。。我补充一下哈。我就马虎了,系统升级成了8.0了,但是pods里边还是写的7.0.此时也会报和error3一样的错误,说某个第三方安装不起。
  • 豆瓣菜:aowangdeiMac:~ jakie$ sudo gem install cocoapods
    Fetching: i18n-0.7.0.gem (100%)
    Successfully installed i18n-0.7.0
    Fetching: thread_safe-0.3.5.gem (100%)
    Successfully installed thread_safe-0.3.5
    Fetching: tzinfo-1.2.2.gem (100%)
    Successfully installed tzinfo-1.2.2
    Fetching: minitest-5.9.0.gem (100%)
    Successfully installed minitest-5.9.0
    Fetching: concurrent-ruby-1.0.2.gem (100%)
    Successfully installed concurrent-ruby-1.0.2
    Fetching: activesupport-5.0.0.gem (100%)
    ERROR: Error installing cocoapods:
    activesupport requires Ruby version >= 2.2.2.
    我在安装CocoaPods时报错显示安装错误,现在的系统版本是OS X EI Capitan;我用的安装命令是:sudo gem install cocoapods;我本来想看下用这个命令安装会出现什么情况,现在我在用:sudo gem install -n /usr/local/bin cocoapods命令还是出现上面那个错误,是因为我之前用了第一个命令所以现在安装就会失败了嘛
    沐风一月:@jakie_king  怎么升级ruby呢?我怎么搞都还是没成功
    豆瓣菜:@ce66d7b1058c 已经OK了 谢谢啦
    大卫石:@jakie_king更新一下ruby
  • 雷鸣1010:pod setup 之后,报错error: RPC failed; result=56, HTTP code = 200,楼主见过么
    9d426ee34834:@雷鸣1010 我也是这个错误 你搞定没有
    雷鸣1010:@待绝笔墨痕干 [!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master

    Cloning into 'master'...
    error: RPC failed; result=56, HTTP code = 200
    fatal: The remote end hung up unexpectedly
    fatal: early EOF
    fatal: index-pack failed 这是完整的报错,我换了个网速好的地方,还是这样的错误,求救
    2f3e8481036f:@雷鸣1010 外网比较卡,重新安装就可以了。
  • LoveY34:pod setup 执行的时候提示“-bash: pod: command not found”,是什么原因啊?
    88182a062277:@lovey1314看一下输入的是 $ pod setup 还是 pod setup。
    75afc06dcc73:@Lylhf 无效的命令
  • 奋斗的小蜗牛_:copy 的完美.一模一样.真特么6
  • 有点精分:谢谢,很有帮助,想引用一下您的这篇博客,如果您不同意的话,我会立即删除的.
  • hrscy:$ sudo rm -rf ~/.cocoapods/repos/master
    $ pod setup
    执行上面的命令还是不行,还是会报上面的错误
    hrscy:@推遍天下无敌手 解决了,不过忘记用的什么方法了。。。
    推遍天下无敌手:@hrscy 我也遇到相同的错误,问下解决了吗
  • coderWen:牛逼,写得很详细,正好解决我的问题
  • 019678cc7f60:怎么解决
  • 019678cc7f60:pod install --no-repo-update之后报错:
    [!] The dependency `AFNetworking (~> 2.0)` is not used in any concrete target.
    这是什么原因,谢谢
    eryuxinling:@gongchengshi targetName,是什么?
    019678cc7f60:@楚天书舒 完美
    咖咖嘻:@gongchengshi
    没遇到过这种问题,
    http://blog.csdn.net/ross_r/article/details/50478859
    这是不是答案,可以试一下

本文标题:CocoaPods 安装 使用

本文链接:https://www.haomeiwen.com/subject/kiadhttx.html