Flutter踩坑-更新pub之一波三折

「这是我参与2022首次更文挑战的第2天,活动详情查看:2022首次更文挑战

踩坑

在更新image_picker的路上,简直是一波三折,足足花了我一整天的时间来搞这些,这里简单记录下过程,希望能对大家有所帮助。 ​

安装image_pickerpub get的时候发生了错误:

Automatically assigning platform `iOS` with version `9.0` on target `Runner` because no platform was specified. Please specify a
复制代码

解决方法是:找到Flutter中的Podfile文件,指定iOSplatform的版本

image.png

接着继续pub get出现了以下错误:

 undefined method `each_child' for #<Dir:0x007f845dce4080>
 Did you mean?  each_slice
复制代码

查了些资料,这里是说each_child方法找不到, 这个方法的调用是在 flutter_tools/bin/podhelper.rb. 继续看报错信息:

/Users/xxx/.rvm/gems/ruby-2.4.1@global/gems/cocoapods-core-1.10.1/lib/cocoapods-core/podfile.rb:179:in `post_install!'
/Users/xxx/.rvm/gems/ruby-2.4.1@global/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb:897:in `run_podfile_post_install_hook'
/Users/xxx/.rvm/gems/ruby-2.4.1@global/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb:885:in `block in run_podfile_post_install_hooks'
/Users/xxx/.rvm/gems/ruby-2.4.1@global/gems/cocoapods-1.10.1/lib/cocoapods/user_interface.rb:145:in `message'
复制代码

Ruby安装

each_child这个方法在Ruby的2.6的版本中才出现,于是我就查了一下当前的Ruby版本,果然当前是2.4.1版本,此时我就要开始升级Ruby了。在升级的过程中也踩了一些坑,我使用的是RVM来更新Ruby

  1. 查看历史Ruby版本:
rvm list known
复制代码

image.png 我一般使用最新版本的上一个版本,所以我就执行安装的版本为2.7.2

  1. 指定安装的版本
rvm install ruby-2.3.1
复制代码

结果提示我,要安装先去升级homebrew,好吧,那我就按照提示来

image.png

  1. 更新brew,在更新的过程提示我执行下面的这个命令

image.png

  1. 按照提示继续克隆homebrew-core
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
复制代码

但是吧,默认关联 git 仓库是国外的,速度慢,还经常被墙,导致 early EOF 之类的错误,反正我试了不下5次都是这个提示,后面我就放弃了,最后选择使用国内中科大的临时镜像。

image.png

  1. 我卸载了之前的homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
复制代码
  1. 安装新的homebrew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
复制代码
  1. 选择中科大的下载源,这里比较友好呀,好多中文提示。再也不用对着有道翻译来了。这里一共有5个下载源中科大、清华大学、北京外国语大学、腾讯和阿里巴巴。参考了其他的意见,最后选择了大家都使用的中科大的镜像。

  2. next->根据提示来:

source /Users/xxx/.zprofile
复制代码
  1. 查看下载的brew的版本,如果有版本信息,说明已经下载完成
brew -v
复制代码
  1. 此时再来更新Ruby,默认更新到最新的版本
rvm install ruby
复制代码

image.png

此时终于安装完成。然后再回到Flutter项目中Pub get

image.png

喜大普奔~~~~~~

猜你喜欢

转载自juejin.im/post/7054889474777415687