安装Cocoapods,以及其中出现的问题

若是须要回退pod版本,打包pod等,能够参考本人的这篇博客

pod回退,打包开源pod,打包静态动态库等

 

添加一个连接http://www.tuicool.com/articles/7VvuAr3

更新升级10.11 cocoapods安装出问题最简单的解决方法php

这是由于10.11把cocoapods直接干掉了html

sudo gem install -n /usr/local/bin cocoapods 再加一句,完美解决 sudo xcode-select --switch /Applications/Xcode.app 

使用CocoaPods作依赖管理,使咱们的工程更加自动化的、集中的、简单直观的管理第三方开源库。你不用下载开源库的源代码引入工程,不用向工 程中添加Framework,不用解决开源库和开源库以及开源库和工程之间的依赖、重复问题,也不用管开源库更新等一系列问题。有了CocoaPods, 你只管任性,CocoaPods会为你作好一切。ios

更新Ruby

你须要会简单的使用命令行工具
CocoaPods惟一的限制就是在Ruby下运行,如今OS X都预装了Ruby,因此你只须要更新RubyGems到最新版本。
打开终端(control + space 真的很好用),而后输入以下的命令:
git

sudo gem update --system 

会要你输入密码:
注意在终端中密码不显示字符,只要输完后按回车便可
用淘宝替换Ruby的默认源,替换命令以下:
github

gem sources --remove https://rubygems.org///等有反应以后再敲入如下命令gem sources -a http://ruby.taobao.org///验证是否替换成功能够执行gem sources -l 

如图所示则证实替换成功segmentfault

安装CocoaPods

在终端中输入以下命令:xcode

sudo gem install cocoapods 

安装过程是这样的:ruby

安装完成如上图所示服务器

在终端中输入以下命令来完成安装:app

//将 CocoaPods Specs repository复制到你电脑上~/.cocoapods目录下pod setup 

它须要一点时间来完成,你等就是了
若是安装失败 ~/.cocoapods 里面是空的,就须要从新setup
命令以下:

pod repo remove master   pod setup 

完毕以后这个文件夹大概有 100多M,须要花费比较多时间,请耐心等待。
到这里你已经成功安装了CocoaPods!

建立配置Podfile

Xcode新建一个HelloWorld工程
打开终端,进入HelloWord工程目录下:

//工程的路径也能够直接拖进来     cd /Users/lifupeng/Desktop/HelloWorld 

在HelloWorld工程下建立一个默认的Podfile
执行命令:

pod init 

用Xcode打开Podfile命令:

open -a Xcode Podfile 

Podfile是这样的:

Xcode打开Podfile

修改类库支持的最低iOS版本

将# platform:ios, "6.0"修改为 #platform :ios, "7.0"告诉CocoaPods你的工程是运行在iOS7下 

为了让CocoaPods的引入不显示警告,在Podfile最上方加上:

inhibit_all_warnings!// 也能够单独设置打开编译警告就行了pod 'Alamofire', '~> 3.0.0-beta.3', :inhibit_warnings => true 

最后Podfile配置是这样的:

Podfile配置

搜索第三方开源库

以搜索AFNetworking为例,搜索命令以下:

pod search AFNetworking 

搜索结果以下:

pod search AFNetworking结果


把下面内容:

pod 'AFNetworking', '~> 2.5.0' 

添加到Podfile中

target 'HelloWorld' dopod 'AFNetworking', '~> 2.5.0'end 

而后保存关闭

安装开源库到你的工程中。

在终端中输入下面命令:(确保在终端的路径在项目目录下):

pod install 

至此 你已经成功的把AFNetworking添加到工程中了

[!] From now on use `ShowTracker.xcworkspace` 

正如上面的警告提醒,从如今开始,你必须使用HelloWorld.xcworkspace来打开该项目。

为了让CocoaPods的引入不显示警告,在Podfile最上方加上:

inhibit_all_warnings! 

从新运行pod install,编译项目,此时你应该看到警告已经不显示了。

PS: 对Podfile修改安装以后编译项目,可能会出现以下警告 :

   The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation. 

此时,正确的作法是:

1.Project Cleanup2.Remove all libPods*.a in  Linked Frameworks and Libraries3.Update CocoaPods using the command  pod install 

测试:
   添加 #import <AFNetworking.h>头文件
今后引用第三方库如此简单,但愿各位用的爽

CocoaPods经常使用命令

一、pod install 

根据Podfile文件指定的内容,安装依赖库,若是有Podfile.lock文件并且对应的Podfile文件未被修改,则会根据Podfile.lock文件指定的版本安装。
每次更新了Podfile文件时,都须要从新执行该命令,以便从新安装Pods依赖库。

二、pod update 

若果Podfile中指定的依赖库版本不是写死的,当对应的依赖库有了更新,不管有没有Podfile.lock文件都会去获取Podfile文件描述的容许获取到的最新依赖库版本。

三、pod search 

命令格式为:

$ pod search AFNetworking  AFNetworking为参数 

四、查看版本

pod --version 

五、卸载 cocoapods

sudo gem uninstall cocoapods 

今天比较闲,就把CocoaPods升级到0.36.0正式版(之前写Swift的时候用的预览版)。而后就郁闷了,无论安装什么第三方都会出现相似于:
[!] Unable to satisfy the following requirements: - `AFNetworking (~> 2.5.1)

 一通的搜索后找到缘由,由于GFW的缘故。解决方法: pod repo remove master pod repo add master https://gitcafe.com/akuandev/Specs.gitpod repo update 

 

 

常见问题

1.
[!] Invalid
Podfile file: undefined local  variable or method `en_US' for #<Pod::Podfile:0x00000102a5d8b0>.  Updating CocoaPods might fix the issue.

缘由:单引号格式,多是手动输入致使
解决办法:系统偏好设置-键盘-文本-将“使用智能引号和破折号”一项取消勾选-再将podfile里面的单(双)引号修改一下

2.ArgumentError - invalid byte sequence in US-ASCII
缘由:字符集错误
解决办法:
使用locale命令查看当前的字符集,若是都是zh,须要执行如下命令:
export LC_ALL=en_US.UTF-8
export.UTF-8
而后再使用locale命令查看,已经改过来了

  1. [!] The YMTea [Debug] target overrides the OTHER_LDFLAGS  build setting defined in `Pods/Target Support  Files/Pods/Pods.debug.xcconfig'. This can lead to problems with the  CocoaPods installation

    • Use the $(inherited) flag, or

    • Remove the build settings from the target.

[!] The YMTea [Release] target overrides the OTHER_LDFLAGS  build setting defined in `Pods/Target Support  Files/Pods/Pods.release.xcconfig'. This can lead to problems with the  CocoaPods installation

- Use the `$(inherited)` flag, or - Remove the build settings from the target. 

缘由:我是在已有项目中集成Cocoapods的时候遇到这个问题,缘由是项目 Target 中作了一些设置,CocoaPods 也作了默认的设置,若是两个设置结果不一致,就会形成问题。
解决方法:我想要使用 CocoaPods 中的设置,分别在个人项目中定义
PODS_ROOTOther Linker Flags的地方(build settings),把他们的值用$(inherited)替换掉,进入终端,执行 pod update
警告没了,回到 Xcode,build经过。
网上还流行另一种简单粗暴的方法:点击项目文件 project.xcodeproj,右键
显示包内容,用文本编辑器打开project.pbxproj,删除OTHER_LDFLAGS的地方,保存(这种我没试过)

4.
[!] Oh no, an error occurred.

It appears to have originated from your Podfile at line 2.

Search for existing GitHub issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=%2FUsers%2Fxiao6%2FMusic%2FGI06%E5%AE%9E%E8%AE%AD%E8%8A%B8%E8%8C%97%E8%8C%B6%E5%8F%B6%2FYMTea%2FPodfile%3A2%3A+syntax+error%2C+unexpected+%27%3A%27%2C+expecting+end-of-input%0Aplatform+%3A+ios%2C+%277.0%27%0A++++++++++%5E&type=Issues

If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new

Be sure to first read the contributing guide for details on how to properly submit a ticket:
https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md

Don't forget to anonymize any private data!

缘由:这个问题比较蛋疼,弄了很久,仔细看发现就是由于Podfile文件里面 platform 那一行 冒号和ios之间多了一个空格。。。。其实这个错误在报错的时候ruby已经给出了,只是一开始没有好好看:


03.png

6.安装出现问题

我如今须要安装Cocoapods 。gem的镜像一景更换为淘宝的了。
执行
sudo gem install cocoapods出现错误:

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

我估计是gem版本没有更新。执行sudo gem update --system,又出现了错误

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

解决:

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

7.updata时候没反应,须要等好久

解决:

使用pod install --verbose --no-repo-update

或者等一段时间页能够成功

附:如何使用CocoaPods的镜像索引:

全部项目的Podspec文件都托管在https://github.com/CocoaPods/Specs,
第一次执行pod setup时,CocoaPods会将这些podspec索引文件更新到本地的~/.cocoapods目录下,
这个索引文件比较大,因此第一次更新时很是慢.
友好人士在国内的服务器创建了Cocoapods索引库的镜像,
因此执行索引跟新操做时候会快不少.具体操做方法以下:
$ pod repo remove master
$ pod repo add master https://gitcafe.com/akuandev/Specs.git
$ pod repo update
这是使用gitcafe上的镜像,将以上代码中的 https://gitcafe.com/akuandev/Specs.git
替换成 http://git.oschina.net/akuandev/Specs.git 便可使用oschina上的镜像。

 

参考:

http://www.jianshu.com/p/5fc15906c53a#

https://segmentfault.com/q/1010000003877063

http://www.cocoachina.com/bbs/read.php?tid-314045.html

相关文章
相关标签/搜索