安装cocoapods以及正确在react-native项目中应用

前言:公司配的mac,由于版本等原因导致pod install失败,在网上搜索了很多解决方案,也试了很多方法。然而并没有什么卵用,最后只能卸掉cocoapods 重新安装属于自己的包管理工具。

一,卸载cocoapods

1,首先,检查自己是否有没有安装过pod:


~which pod 

/usr/local/bin/pod


2,移除pod,输入密码:
  ~ sudo rm -rf /usr/local/bin/pod

Password:


3,查看cocoapods安装了哪些东西:
  ~ gem list
显示如下:
......
claide (1.0.2)
cocoapods (1.4.0)
cocoapods-core (1.4.0)
cocoapods-deintegrate (1.0.2)
cocoapods-downloader (1.1.3)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.0)
cocoapods-stats (1.0.0)
cocoapods-trunk (1.3.0)
cocoapods-try (1.1.0)
colored2 (3.1.2 )

......


4,逐个移除cocoapods相关文件:
  ~ sudo gem uninstall cocoapods -v 1.4.0
in addition to the gem? [Yn]  y
根据提示输入y,允许卸载:
Removing pod
Removing sandbox-pod

Successfully uninstalled cocoapods-1.4.0


完成后,继续卸载剩下的cocoapods文件,XXX为文件名,需要你自己修改相应的文件名:

  ~ sudo gem uninstall cocoapods-XXX


5,查看是否卸载干净
  ~ gem list

只要文件中没有cocoapods的文件就可以了。

二,修改镜像源

1,查看源:


  ~ gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.org

这里我的源位置不是https://gems.ruby-china.org/,需要修改:


2,移除源:
  ~ gem sources --remove https://gems.ruby-china.org

https://gems.ruby-china.org removed from sources


查看是否移除成功:
  ~ gem sources -l   
*** CURRENT SOURCES ***

没有即证明移除


3,添加源,网上有提供淘宝源的,但好像淘宝源不能用了,以下建议:

  ~ gem sources -a https://gems.ruby-china.org/


查看是否添加成功:

  ~ gem sources -l   
*** CURRENT SOURCES ***
https://gems.ruby-china.org/

出现上述即为add成功


三,安装cocoapods,项目应用

1,安装,根据提示输入密码
  ~ sudo gem install cocoapods
Password:
Fetching: cocoapods-core-1.5.2.gem (100%)
Successfully installed cocoapods-core-1.5.2
Fetching: cocoapods-deintegrate-1.0.2.gem (100%)
Successfully installed cocoapods-deintegrate-1.0.2
......
ERROR:  While executing gem ... (Errno::EPERM)

Operation not permitted - /usr/bin/xcodeproj


咦?出现个错误,没关系,接下来这样做:


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


2,接下来输入
  ~ pod setup
Setting up CocoaPods master repo
  $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
  Cloning into 'master'...
  remote: Counting objects: 2141415, done.        
  remote: Compressing objects: 100% (398/398), done.        
  Receiving objects:   0% (9227/2141415), 1.84 MiB | 10.00 KiB/s  

接着,耐心等待~~~


四,其他问题

1, YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0).

解决办法:

$ rvm list known
$ rvm install 2.4.1 # 这里可以安装你需要的版本  但是需要安装2.0以上的
$ rvm use 2.4.1 --default

2,unable to access 'https://github.com/CocoaPods/Specs.git/': SSLRead() return error -9806


或者出现如下错误提示:

[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress


Cloning into 'master'...

remote: Counting objects: 2143217, done.        

remote: Compressing objects: 100% (348/348), done.        

error: RPC failed; 

解决办法:

git config --global http.proxy 更改代理

pod setup 应用pod

git config --global --unset http.proxy 取消代理

再查询,已经没有了代理,  后成功安装。
3,
[!] Error installing BaiduMapKit

[!]/usr/bin/git clone https://github.com/BaiduLBS/BaiduMapKit.git 

/var/folders/qx/xn6yzj497sb42jwz9z6nyyjm0000gn/T/d20180516-70123-1uz7sj3 

--template= --single-branch --depth 1 --branch 3.2.1


Podfile文件的内容改为
use_frameworks! platform :ios, ‘8.3‘ target "baidu" do pod 'BaiduMapKit’,’2.10.2’ end BaiduMapKit版本号根据你的自定义。

执行pod install

还是不行的话,是因为pod install命令被墙了,换成pod install --verbose --no-repo-update搞定!






























猜你喜欢

转载自blog.csdn.net/qq_37336604/article/details/80340968