您的位置:首页 > 其它

关于cocoapods的安装使用注意的事项(各种出错的总结)

2017-03-30 14:48 399 查看
原文网址:http://blog.csdn.net/objectivepla/article/details/50037971

上面是原文网址,我在它的基础上进行了,整理,详细如下:

// pod: command not found 出现错误的解决方案:

如何在Mac OS X上安装
Ruby运行环境

  对于新入门的开发者,如何安装
Ruby和Ruby Gems 的运行环境可能会是个问题,本页主要介绍如何用一条靠谱的路子快速安装

Ruby 开发环境。

此安装方法同样适用于产品环境!

系统需求

首先确定操作系统环境,不建议在 Windows 上面搞,所以你需要用:

Mac OS X

任意
Linux 发行版本(Ubuntu,CentOS, Redhat, ArchLinux …)

强烈新手使用 Ubuntu 省掉不必要的麻烦!

以下代码区域,带有 打头的表示需要在控制台(终端)下面执行(不包括 符号)

步骤0 - 安装系统需要的包

  # For Mac

  # 先安装 Xcode 开发工具,它将帮你安装好 Unix 环境需要的开发包

步骤1 - 安装 RVM

RVM 是干什么的这里就不解释了,后面你将会慢慢搞明白。

    $ curl -L https://get.rvm.io | bash -s stable

期间可能会问你sudo管理员密码,以及自动通过homebrew安装依赖包,等待一段时间后就可以成功安装好 RVM。

然后,载入 RVM 环境(新开 Termal 就不用这么做了,会自动重新载入的)

    $ source ~/.rvm/scripts/rvm

检查一下是否安装正确

    $ rvm -v

    rvm 1.22.17 (stable) by Wayne E. Seguin wayneeseguin@gmail.com, Michal Papis mpapis@gmail.com [https://rvm.io/]

步骤2 - 用 RVM 安装
Ruby 环境

列出已知的Ruby版本

   $ rvm list known

可以选择现有的rvm版本来进行安装(下面以rvm 2.0.0版本的安装为例)

    $ rvm install 2.0.0

同样继续等待漫长的下载,编译过程,完成以后,Ruby,

Ruby Gems 就安装好了。

另附:

查询已经安装的Ruby

  $ rvm list

卸载一个已安装版本

$ rvm remove 1.9.2

步骤3 - 设置
Ruby 版本

RVM 装好以后,需要执行下面的命令将指定版本的
Ruby 设置为系统默认版本

    $ rvm 2.0.0
4000
–default

同样,也可以用其他版本号,前提是你有用 rvm install 安装过那个版本

这个时候你可以测试是否正确

    $
Ruby -v

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

    $ gem -v

    2.1.6

这有可能是因为Ruby的默认源使用的是cocoapods.org,国内访问这个网址有时候会有问题,网上的一种解决方案是将远替换成淘宝的,替换方式如下:

   $gem source -r https:// href="http://codecloud.net/tag/Ruby" target=_blank>Rubygems.org/

  $ gem source -a https:// href="http://codecloud.net/tag/Ruby" target=_blank>Ruby.taobao.org

要想验证是否替换成功了,可以执行:

    $ gem sources -l

正常的输出结果:

      CURRENT SOURCES            

      http://Ruby.taobao.org/ 


接下来就是安装cocoapods


2、下载安装CocoaPods

终端输入:sudo gem install cocoapods

3、使用CocoaPods

a 新建一个项目,名字PodTest

b 终端中,cd到项目总目录(注意:包含PodTest文件夹、PodTest.xcodeproj、PodTestTest的那个总目录)

[objc] view plaincopyprint?在CODE上查看代码片派生到我的代码片

cd /Users/lucky/Desktop/PodTest  

c 建立Podfile(配置文件)

接着上一步,终端输入 vim Podfile 创建Podfile文件

键盘输入 i,进入编辑模式,输入

platform :ios, ‘7.0’

pod ‘MBProgressHUD’, ‘~> 0.8’

然后按Esc,并且输入“ :”号进入vim命令模式,然后在冒号后边输入wq

注意:键盘输入 :后,才能输入wq。回车后发现PodTest项目总目录中多一个Podfile文件

激动人心的时刻到了:确定终端cd到项目总目录,然后输入 pod install,等待一会,大约3分钟。

问题解决:

1,有时候会出现:Error fetching https:// href="http://codecloud.net/tag/Ruby" target=_blank>Ruby.taobao.org/:
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://Ruby.taobao.org/specs.4.8.gz)

失效了 换成这个:

gem sources -a https://gems. href="http://codecloud.net/tag/Ruby" target=_blank>Ruby-china.org/

https://gems.Ruby-china.org/

2, The dependency AFNetworking (~> 3.1.0) is not used in any concrete target.

原因:CocoaPods升级后,Podfile文件的内容格式要求发生了变化,必须指出指出所用第三方库的target。

解决步骤:

(1)检查CocoaPods的版本

        pod --version

  (2) 升级或安装最新版本(目前版本1.0.1)

       注意:如果cocoapods已经是1.0.1版本,则跳过该步骤直接进入第三个步骤。

       升级命令:sudo gem update -n /usr/local/bin --system

    安装命令:sudo gem install -n /usr/local/bin cocoapods

 (3)修改Podfile的内容

    修改前的Podfile文件的内容:      

platform:ios,’7.0′

pod ‘MJRefresh’, ‘~> 3.1.0’

pod ‘SDWebImage’, ‘~> 3.7.6’

pod ‘SVProgressHUD’, ‘~> 2.0.3’

pod ‘AFNetworking’, ‘~> 3.1.0’

  修改后的Podfile文件的内容:

复制代码

platform:ios,’7.0′

target "MyProject" do

pod ‘MJRefresh’, ‘~> 3.1.0’

pod ‘SDWebImage’, ‘~> 3.7.6’

pod ‘SVProgressHUD’, ‘~> 2.0.3’

pod ‘AFNetworking’, ‘~> 3.1.0’

end

 4, 在Podfile文件中需要明确指出使用第三方库的target,这里target后面跟的就是自己项目本身的Target;也就是项目中的tagrets中的那个项目名称。

[!] Unable to satisfy the following requirements:

MJRefresh (~> 3.1.0) required by Podfile
None of your spec sources contain a spec satisfying the dependency: MJRefresh (~> 3.1.0).

You have either:

out-of-date source repos which you can update with pod repo update.
mistyped the name or version.
not added the source repo that hosts the Podspec to your Podfile.
Note: as of CocoaPods 1.0, pod repo update does not happen on pod install by default.

来发现这是个已知的BUG, CocoaPods的版本库是有缓存的, 但在使用pod指令更新版本库时会出现冲突, 导致更新并不能如期完成, 需要手动删除本地缓存, 再进行更新.

具体方法:

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

$ pod setup

5, 5.你打开你的Podfile文件你会发现,类似这样的内容

platform:ios,’7.0’

pod ‘SDWebImage’,’3.6’

cocoapods升级之后到最新版本,Podfile里的内容必须明确指出所用第三方库的target,否则会出现The dependency “ is not used in any concrete target这样的错误。

6.可以这样修改Podfile文件里的内容

platform:ios,’7.0’

target “Register” do

pod ‘SDWebImage’,’3.6’

end

注意 target “Register” do 中的"Register"一般是你的项目名称

7.cd到根目录再执行命令

$ pod install

耐心等待一会儿,就把你想要的第三方导入项目了

8,

Unable to satisfy the following requirements:

SDWebImage (= 3.6) required by Podfile
SDWebImage (~> 3.7) required by UIActivityIndicator-for-SDWebImage (1.2)
[!] Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes in your editor of choice.

原因是要添加的类库已经有最新版本推出,而Podfile文件并没有更改其下载版本(Podfile文件过期),于是获取安装数据失败。

因此我们要用update命令获取最新版本的类库:

$ pod update

由此可知,出现这个错误的原因是,我本地Podfile文件上的第三方版本太低。解决方案就是,更新一下本地Podfile文件上的第三方版本,也就是pod update –verbose一下。注意一下,这个命令需要很长时间。一直停在这个页面。。。。

大家千万不要关掉页面,等更新完成之后就可以了…

这是这几天出现的问题总结:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: