mac 10.15.7 & Unity 2021.3.14 & XCode 12.4 -> Unity IOS 自动安装 Cocoapods 失败解决方法

自己这两天在用Unity开发IOS时,遇到了安装Cocoapods失败的问题,记录一下问题及解决方法,便于自己后续查看,以及有相同遭遇的人查看

发生场景:打开 unity,触发自动安装 Cocoapods -> 安装失败(各种失败情况在【问题及解决】中都有记录及有解决方法)

原因分析:mac 10.15 自带的 ruby 为 2.6.3,这个版本太低,会导致安装 Cocoapods 出错,及后续 pod 会有问题,我们只需安装新的ruby版本即可

解决流程:安装 rvm -> 安装 ruby-2.7.2 & 启用 -> 安装 Cocoapods

具体解决步骤如下(如安装过程中遇到问题,请查看【问题及解决】):

  1. 安装多ruby管理工具rvm

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

查看rvm已安装的版本

》rvm -v

  1. 安装 ruby-2.7.2

》rvm install ruby-2.7.2

查看已安装的ruby

》rvm list

查看当前系统使用的ruby版本

》ruby -v

如果上面显示版本是旧的2.6的话,请运行下面,让其使用2.7.2

》rvm use 2.7.2

  1. 打开 unity,触发自动安装 Cocoapods(显示 gem install cocoapods)-> 还是安装失败的话,直接看第4步(好像unity中gem认到的还是旧的,而不是我用rvm安装好ruby后新的gem)

  2. 打开 终端 并手动运行安装 Cocoapods(我这里是安装成功了,然后,再打开unity,就不会再弹出安装 cocoapods 了,因为已经手动安装好了)

》gem install cocoapods

  1. 搞定,现在可以用 unity 去导出 XCode 工程了!
    运行前-重点注意:

  2. 运行时,一定不要用 iTerm 运行,请用 终端 运行,否则 rvm install ruby-2.7.2 这一步可能会安装失败

  3. 安装时,会涉及安装第三方库会比较慢,请查看底下 『brew update 更新太慢』的解决方法,去提速,要不然安装会慢到你怀疑人生!

  4. 当到最后一步安装 cocoapods 时,想简单点,就直接 终端 上运行 gem install cocoapods 就好了,可以省去一些麻烦!

【问题及解决】

rvm 安装异常: 出现 curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

解决(设置hosts):

步骤:查找IP -> 修改本地host -> 重装运行第一步curl

  1. 打开 https://site.ip138.com -> 查询 raw.githubusercontent.com 的ip,并记下来(会出现多个ip,我用的第一个出现的ip,ping虽然一般但能下载。用贵州的那个ip,ping虽然最快,但是下载有问题)

  2. 修改host(复制上面记下来的ip到hosts中)

》sudo vim /etc/hosts

182.43.124.6 raw.githubusercontent.com

  1. 重新执行安装

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

  1. 检查是否安装完成

》rvm -v

说明:

安装成功后,rvm会自动在 .bash_profile 中添加如下内容(如果想知道rvm装在哪里了,看这里就知道了)

\[ -s "$HOME/.rvm/scripts/rvm" \]\] \&\& source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session \*as a function\* ruby-2.7.2 安装异常:出现 No binary rubies available for: osx/10.15/x86_64/ruby-2.7.2. Failed to update Homebrew, follow instructions at https://docs.brew.sh/Common-Issues and make sure \`brew update\` works before continuing. Error running 'requirements_osx_brew_update_system ruby-2.7.2', please read /Users/apple/.rvm/log/1706324534_ruby-2.7.2/update_system.log Requirements installation failed with status: 1. 解决1:brew update 解决2:如果【解决1】后,还是不行,请查看你是否使用了 iTerm,请换成 终端 后再重新运行 rvm install ruby-2.7.2 brew update 更新异常:出现 fatal: unable to access 'https://github.com/shivammathur/homebrew-php/': Failed to connect to github.com port 443: Operation timed out Error: Fetching /usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php failed! Installing from the API is now the default behaviour! You can save space and time by running: brew untap homebrew/core brew untap homebrew/cask 解决: 》sudo vim /etc/hosts 140.82.114.4 github.com brew update 更新太慢: 解决: # 改变 brew 源(由默认的国外源,改为国内源) cd $(brew --repo) git remote set-url origin https://mirrors.ustc.edu.cn/brew.git # 改变 brew-core 源 cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git # 完成换源之后,再执行更新指令一次(速度就很快了) brew update Cocoapods 安装异常:出现 fatal error: 'ruby/config.h' file not found 解决(ruby 加软链): 》cd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby 》sudo ln -sf ../../../../Headers/ruby/config.h Cocoapods 安装异常:出现 make: \*\*\* No rule to make target \`/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19/ruby/config.h', needed by \`AbstractMemory.o'. Stop. 解决(ruby 加软链): 》cd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 》sudo ln -sf universal-darwin20 universal-darwin19 Cocoapods 安装异常:出现 ERROR: Error installing cocoapods: The last version of drb (\>= 0) to support your Ruby \& RubyGems was 2.0.6. Try installing it with \`gem install drb -v 2.0.6\` and then running the current command again drb requires Ruby version \>= 2.7.0. The current ruby version is 2.6.3.62. 解决: 安装 ruby-2.7.2 版本(请查看开头 2. 安装多ruby管理工具、新版ruby) Cocoapods 安装异常:出现 You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory. 出现:unity 打开时,自动弹出安装 cocoapods 时出现 解决:直接关闭 unity,改用打开系统 终端 直接运行命令 gem install cocoapods 就行了 原因:unity 打开时,他的 gem 命令好像用的还是旧的,会自动安装到/Library库中,不是我新装好的 gem,导致出错(怎么在unity中让gem运行时是新的,弄了一会没弄出来,算了,先不管了,终端能安装也行了)

------ 其它 ------

Unity开发Ios部分流程:安装 XCode -> 进入Unity,自动安装Cocospods -> 导出XCode工程 -> XCode打开工程&真机测试 -> 上传appstore

说明:mac 10.15.7 + unity 开发ios,需要安装 XCode 12.4 及以下版本(更高的版本需要更高的系统)

XCode与Mac版本对应网址:https://xcodereleases.com/

XCode各大版本下载网址:https://developer.apple.com/download/all/?q=xcod

相关推荐
一棵树长得超出它自己13 分钟前
Allure安装与使用【macOS】
macos
三金C_C1 小时前
Mac配置开发环境
macos·开发环境
这个昵称也不能用吗?3 小时前
react-native搭建开发环境过程记录
前端·react native·cocoapods
百锦再3 小时前
Android Studio 项目文件夹结构详解
android·java·ide·ios·app·android studio·idea
season_zhu4 小时前
iOS开发:关于URL解析
ios·json·swift
iOS大前端海猫5 小时前
深入解析 Swift 中的并发属性包装器:@Actor、@MainActor 和 @GlobalActor
ios·app
zaizai10076 小时前
Unity 一些小功能(屏幕画画,)
unity
溪饱鱼6 小时前
DHgate爆火背后的技术原因
android·前端·ios
增强7 小时前
腾讯云 人脸核身 Flutter 插件功能开发(一 IOS 端实现)
ios
归海_一刀9 小时前
【Unity动态换装骨骼合并】
unity·c#·游戏引擎