cocoapods安装问题

CocoaPods简介

  • CocoaPods是一个用Ruby写的、负责管理iOS项目中第三方开源库的工具,CocoaPods能让我们集中的、统一管理第三方开源库,为我们节省设置和更新第三方开源库的时间。
  • Mac电脑自带Ruby环境。
  • CocoaPods需要最低Ruby环境,可以升级Ruby版本。

CocoaPods安装

1. 安装Homebrew,通过Homebrew升级ruby版本

  • 使用国外资源安装raw.githubusercontent.com:
    • 终端键入
     /bin/bash -c "$(curl -fsSL    https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
    • 报错:Failed to connect to raw.githubusercontent.com port 443:之类的错误
    • 解决:
    • 系统偏好设置->网络->选择当前连接的网络->高级->DNS->添加+8.8.8.8114.114.114.114->设置完成一定要点击应用
    • 终端键入nslookup,显示如下:
      lhzl_lgq@LHZLdeMac-mini ~ % nslookup
      > raw.githubusercontent.com
      Server:        114.114.114.114
      Address:   114.114.114.114#53
    
      Non-authoritative answer:
      Name:  raw.githubusercontent.com
      Address: 185.199.108.133
      Name:  raw.githubusercontent.com
      Address: 185.199.111.133
      Name:  raw.githubusercontent.com
      Address: 185.199.109.133
      Name:  raw.githubusercontent.com
      Address: 185.199.110.133
      > 
    
    • ping一下四个IP,选择延迟最快的,copy
    • 终端键入vi /etc/hosts:
      ##
      # Host Database
      #
      # localhost is used to configure the loopback interface
      # when the system is booting.  Do not change this entry.
      ##
      127.0.0.1       localhost
      255.255.255.255 broadcasthost
      ::1             localhost
      
      # GitHub Start
      185.199.111.133   raw.githubusercontent.com   #(这个IP就是上面copy的)
      # GitHub End
      ~                                                                                                                                                                                                                                         
      "/etc/hosts" 13L, 286C
      
    • Esc退出vim编辑模式,:wq退出vim
    • 重新键入
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
    • 安装成功
    • curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443,报这个错,直接换国内源安装。
  • 如果使用国外源不成功,可以使用国内源安装Homebrew:
    • 终端键入:
      /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
      
    • 安装成功

2.安装rvm,通过rvm升级ruby版本

  • 键入
curl -L get.rvm.io | bash -s stable
  • 如果报错curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused,则按照上面安装Homebrew国外源的办法,设置DNS和修改/etc/hosts
  • 下载完成,加载 RVM后才能使用。键入
source ~/.rvm/scripts/rvm
  • 检查安装是否成功
rvm -v
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

3.安装ruby

  • 使用RVM工具安装 Ruby
// 列出已知的ruby版本
rvm list known
// 安装 x.x.x为Ruby版本号
rvm install 3.0.0
  • 使用Homebrew工具安装 Ruby
brew install ruby
  • 查看ruby版本
ruby -v
  • 更换ruby源
sudo gem update --system
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
gem sources -l #查看当前源

4.安装cocoapods

  • 安装CocoaPods
    sudo gem install -n /usr/local/bin cocoapods
    
  • 安装本地库
    pod setup
    

―――――――――――――――――――――――――――――

其他cocoapods相关问题

1.podfile更新时候,遇到下面问题:

### Report

* What did you do?
* What did you expect to happen?
* What happened instead?

### Stack

   CocoaPods : 1.12.1
        Ruby : ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [arm64-darwin22]
    RubyGems : 3.2.3
        Host : macOS 13.2 (22D49)
       Xcode : 14.1 (14B47b)
         Git : git version 2.37.1 (Apple Git-137.1)
Ruby lib dir : /Users/liujianlong/.rvm/rubies/ruby-3.0.0/lib
Repositories : cocoapods - git - https://github.com/CocoaPods/Specs.git @ 1b3acb34cfa36a4f71d7a7e568bbc7cf39202c9a
trunk - CDN - https://cdn.cocoapods.org/

### Plugins
cocoapods-deintegrate : 1.0.5
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.1
cocoapods-trunk       : 1.6.0
cocoapods-try         : 1.2.0

### Podfile
ruby
platform :ios, '12.3'
target 'socksTest' do
pod 'SDWebImage', '~> 5.13.2'
pod 'SnapKit', '~> 5.6.0'
pod 'BGFMDB', '~> 2.0.13'
pod 'MJExtension', '~> 3.4.1'
pod 'Masonry', '~> 1.1.0'
pod 'MJRefresh', '~> 3.5.0'
pod 'Moya', '~> 15.0.0'
pod 'TCCKit', '~> 1.0.5'
end

### Error
Encoding::CompatibilityError - incompatible character encodings: UTF-8 and ASCII-8BIT
/Users/liujianlong/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/fileutils.rb:1564:in `join'
/Users/liujianlong/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/fileutils.rb:1564:in `join'
/Users/liujianlong/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/fileutils.rb:1224:in `path'
...............

[!] Oh no, an error occurred.
Search for existing GitHub issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=incompatible+character+encodings%3A+UTF-8+and+ASCII-8BIT&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!

Looking for related issues on cocoapods/cocoapods...
 - Fix compatibility error with Ruby 3.x
   https://github.com/CocoaPods/CocoaPods/pull/11959 [open] [0 comments]
   11 hours ago

 - Encoding::CompatibilityError - incompatible character encodings: UTF-8 and ASCII-8BIT with pod install
   https://github.com/CocoaPods/CocoaPods/issues/10516 [closed] [8 comments]
   16 Feb 2023

 - Encoding::CompatibilityError - incompatible character encodings: ASCII-8BIT and UTF-8
   https://github.com/CocoaPods/CocoaPods/issues/4582 [closed] [9 comments]
   25 Jul 2022

and 14 more at:
https://github.com/cocoapods/cocoapods/search?q=incompatible%20character%20encodings%3A%20UTF-8%20and%20ASCII-8BIT&type=Issues&utf8=✓

解决办法:只需将您的项目绝对目录更改为完全 ascii 字符即可。(不要包含中文)

你可能感兴趣的:(cocoapods安装问题)