我想的是实用主义,不管是啥先用起来,遇到问题逐个解决,需要时再了解原理
1、shared_preferences
shared_preferences
https://pub.flutter-io.cn/packages/shared_preferences/versions
为了解决flutter中软件使用时数据持久化的问题,于是去找了个叫shared_preferences的包。
shared_preferences提供全局单例,看评分是百分百好评,很多博主都推荐。
我在自己的文件中加入了这个包,显示报错说是一个叫cocoapods的东西有问题,要用上这个包必须先更新cocoapods
2、更新cocoapods
CocoaPods就是一个在ios开发中的包管理工具
Warning: CocoaPods is installed but broken. Skipping pod install.
You appear to have CocoaPods installed but it is not working.
This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
This can usually be fixed by re-installing CocoaPods.
To re-install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
我的CocoaPods不能用要更新
然后用了更新命令发现无法更新
网上查资料 说是ruby版本太低
3、更新ruby
我的ruby是什么版本的
(base) mac@macdeMacBook-Air ~ % ruby -v
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]
是 macos 系统化自带的 ruby 版本太低,导致 cocoapods 安装失败。
升级ruby要用HomeBrew更新
4、更新HomeBrew
brew 全称Homebrew,是Mac上的软件包管理工具。
我看了自己的版本
(base) mac@macdeMacBook-Air ~ % brew --version
Homebrew 4.0.1-34-g8ff2e29
Homebrew/homebrew-core (git revision 1655c17518c; last commit 2023-02-17)
Homebrew/homebrew-cask (git revision 2ae6e86efe; last commit 2023-02-16)
于是我更新,总是出错,用了梯子也不行
我看了文章
2023最新总结,Mac下使用Homebrew完全指南!
Homebrew国内如何自动安装(国内地址)(Mac & Linux)
按照文中所述操作搞好了
文中说到 “如果终端使用的是zsh,就写入zsh的配置文件中。”zsh是啥???
5、shell (非主线剧情)
shell就是一个把指令翻译给机器读的解释器
shell 又分 zsh和bash
zsh又兼容bash
我的mac是哪种呢
用这个命令查看
(base) mac@macdeMacBook-Air ~ % echo $0
-zsh
3、更新ruby
回到第三步更新ruby
Mac下升级ruby至最新版本
先查看版本:ruby - v
然后更新:brew install ruby
然后总是显示连接不上,情况如下:
(base) mac@macdeMacBook-Air ~ % ruby -v
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]
(base) mac@macdeMacBook-Air ~ % brew install ruby
==> Downloading https://formulae.brew.sh/api/formula.jws.json
curl: (28) Failed to connect to formulae.brew.sh port 443: Operation timed out
Error: Failure while executing; `/usr/bin/env /opt/homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --user-agent Homebrew/4.0.16-43-gc1fdb59\ \(Macintosh\;\ arm64\ Mac\ OS\ X\ 12.1\)\ curl/7.77.0 --header Accept-Language:\ en --fail --progress-bar --location --remote-time --output /Users/mac/Library/Caches/Homebrew/api/formula.jws.json --compressed --speed-limit 100 --speed-time 5 --progress-bar https://formulae.brew.sh/api/formula.jws.json` exited with 28. Here's the output:
curl: (28) Failed to connect to formulae.brew.sh port 443: Operation timed out
然后用了梯子
然后就搞定了,情况如下:
(base) mac@macdeMacBook-Air ~ % brew install ruby
==> Downloading https://formulae.brew.sh/api/formula.jws.json
######################################################################### 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
##################### 30.0%curl: (28) Operation too slow. Less than 100 bytes/sec transferred the last 5 seconds
Warning: cask.jws.json: update failed, falling back to cached version.
==> Downloading https://formulae.brew.sh/api/cask.jws.json
######################################################################### 100.0%
==> Fetching dependencies for ruby: libyaml, ca-certificates, openssl@1.1 and readline
==> Fetching libyaml
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/libyaml-0.2.5.arm64
######################################################################### 100.0%
==> Fetching ca-certificates
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/ca-certificates-202
######################################################################### 100.0%
==> Fetching openssl@1.1
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/openssl%401.1-1.1.1
######################################################################### 100.0%
==> Fetching readline
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/readline-8.2.1.arm6
######################################################################### 100.0%
==> Fetching ruby
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/ruby-3.2.2.arm64_mo
######################################################################### 100.0%
==> Installing dependencies for ruby: libyaml, ca-certificates, openssl@1.1 and readline
==> Installing ruby dependency: libyaml
==> Pouring libyaml-0.2.5.arm64_monterey.bottle.tar.gz
🍺 /opt/homebrew/Cellar/libyaml/0.2.5: 10 files, 352.9KB
==> Installing ruby dependency: ca-certificates
==> Pouring ca-certificates-2023-01-10.all.bottle.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
🍺 /opt/homebrew/Cellar/ca-certificates/2023-01-10: 3 files, 216.8KB
==> Installing ruby dependency: openssl@1.1
==> Pouring openssl@1.1-1.1.1t.arm64_monterey.bottle.tar.gz
🍺 /opt/homebrew/Cellar/openssl@1.1/1.1.1t: 8,101 files, 18MB
==> Installing ruby dependency: readline
==> Pouring readline-8.2.1.arm64_monterey.bottle.tar.gz
🍺 /opt/homebrew/Cellar/readline/8.2.1: 50 files, 1.7MB
==> Installing ruby
==> Pouring ruby-3.2.2.arm64_monterey.bottle.tar.gz
==> Caveats
ruby is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ruby first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc
For compilers to find ruby you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"
==> Summary
🍺 /opt/homebrew/Cellar/ruby/3.2.2: 16,605 files, 48.3MB
==> Running `brew cleanup ruby`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> ruby
ruby is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ruby first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc
For compilers to find ruby you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"
(base) mac@macdeMacBook-Air ~ %
然后按照最后的提示再操作一下
(base) mac@macdeMacBook-Air ~ % echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc
(base) mac@macdeMacBook-Air ~ %
(base) mac@macdeMacBook-Air ~ % export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
(base) mac@macdeMacBook-Air ~ % export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"
(base) mac@macdeMacBook-Air ~ %
看文章: Mac下升级ruby至最新版本
配置环境变量,此时电脑里有两个ruby 一个是自带的,一个是才装的,要把才装的配置环境变量,取代自带的那个使用,我是把以下命令输入到终端,并且把里面的bash都改成了zsh,因为之前查看我是zsh
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
然后查看版本
(base) mac@macdeMacBook-Air ~ % ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin21]
移出源
gem sources --remove https://rubygems.org/
更换源
gem sources --add https://gems.ruby-china.com/
查看当前gem源,看到这个就对了
(base) mac@macdeMacBook-Air adgame % gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.com/
另外,还可以升级gem,但是我已经是最新的版本了
(base) mac@macdeMacBook-Air ~ % sudo gem update --system
Password:
Latest version already installed. Done.
看文章: mac 教程 安装cocoapod(100%成功)试过无数次
2、更新CocoaPods
再回到第二步
先清除电脑中的的cocoapods
删除旧版本
for i in $( gem list --local --no-version | grep cocoapods );
do
sudo gem uninstall $i;
done
连同配置目录 ~/.cocoapods 一起删除
rm -rf ~/.cocoapods
然后还是没有弄干净
继续这样删
(base) mac@macdeMacBook-Air ~ % which pod
/usr/local/bin/pod
(base) mac@macdeMacBook-Air ~ % sudo rm -rf /usr/local/bin/pod
Password:
(base) mac@macdeMacBook-Air ~ % pod --version
直到
(base) mac@macdeMacBook-Air ~ % pod --version
zsh: command not found: pod
才确认被删干净了
然后安装最新版本的cocoapods
(base) mac@macdeMacBook-Air ~ % sudo gem install -n /usr/local/bin cocoapods
查看版本
(base) mac@macdeMacBook-Air ~ % pod --version
1.12.1
最后可能是网络问题
都搞好了
项目中flutter run还是出错,显示这些玩意
CocoaPods' output:
↳
Preparing
Analyzing dependencies
Inspecting targets to integrate
Using `ARCHS` setting to build architectures of target `Pods-Runner`: (``)
Using `ARCHS` setting to build architectures of target `Pods-RunnerTests`: (``)
Fetching external sources
-> Fetching podspec for `Flutter` from `Flutter`
-> Fetching podspec for `shared_preferences_foundation` from `.symlinks/plugins/shared_preferences_foundation/darwin`
Resolving dependencies of `Podfile`
[!] Couldn't determine repo type for URL: `https://cdn.cocoapods.org/`: Failed to open TCP connection to cdn.cocoapods.org:443 (execution expired)
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/sources_manager.rb:92:in `rescue in cdn_url?'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/sources_manager.rb:73:in `cdn_url?'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/sources_manager.rb:37:in `create_source_with_url'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/sources_manager.rb:22:in `find_or_create_source_with_url'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/installer/analyzer.rb:179:in `block in sources'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/installer/analyzer.rb:178:in `map'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/installer/analyzer.rb:178:in `sources'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/installer/analyzer.rb:1081:in `block in resolve_dependencies'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/user_interface.rb:64:in `section'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/installer/analyzer.rb:1080:in `resolve_dependencies'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/installer/analyzer.rb:125:in `analyze'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/installer.rb:422:in `analyze'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/installer.rb:244:in `block in resolve_dependencies'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/user_interface.rb:64:in `section'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/installer.rb:243:in `resolve_dependencies'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/installer.rb:162:in `install!'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/command/install.rb:52:in `run'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/command.rb:52:in `run'
/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:25:in `load'
/usr/local/bin/pod:25:in `<main>'
Error output from CocoaPods:
↳
[!] `<XCBuildConfiguration name=`Debug` UUID=`331C8088294A63A400263BE5`>` attempted to initialize an object with an unknown UUID. `AE0B7B92F70575B8D7E0D07E` for attribute: `base_configuration_reference`. This can
be the result of a merge and the unknown UUID is being discarded.
[!] `<XCBuildConfiguration name=`Release` UUID=`331C8089294A63A400263BE5`>` attempted to initialize an object with an unknown UUID. `89B67EB44CE7B6631473024E` for attribute: `base_configuration_reference`. This can
be the result of a merge and the unknown UUID is being discarded.
[!] `<XCBuildConfiguration name=`Profile` UUID=`331C808A294A63A400263BE5`>` attempted to initialize an object with an unknown UUID. `640959BDD8F10B91D80A66BE` for attribute: `base_configuration_reference`. This can
be the result of a merge and the unknown UUID is being discarded.
[!] `<PBXNativeTarget name=`RunnerTests` UUID=`331C8080294A63A400263BE5`>` attempted to initialize an object with an unknown UUID. `331C807E294A63A400263BE5` for attribute: `build_phases`. This can be the result of
a merge and the unknown UUID is being discarded.
Error running pod install
Error launching application on iPhone 13 Pro Max.
这和之前有啥不一样么,很崩溃,闹了半天白搞???
我检查flutter doctor
是这样的
(base) mac@macdeMacBook-Air ~ % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 3.10.0-4.0.pre.8, on macOS 12.1 21C52 darwin-arm64,
locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version
33.0.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
[✓] VS Code (version 1.78.0)
[✓] Connected device (3 available)
[!] Network resources
✗ A network error occurred while checking "https://cocoapods.org/":
Operation timed out
✗ A network error occurred while checking "https://github.com/": Operation
timed out
用的是单位的网络,可能是因为网的问题,
回家后用家里的网络
flutter run一次就成功了,也是有点莫名其妙
此时flutter doctor
(base) mac@macdeMacBook-Air ~ % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 3.10.0-4.0.pre.8, on macOS 12.1 21C52 darwin-arm64,
locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version
33.0.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
[✓] VS Code (version 1.78.0)
[✓] Connected device (3 available)
[✓] Network resources
• No issues found!
(base) mac@macdeMacBook-Air ~ %
网络问题也好了
所以我怀疑是网络问题
也许是感动了老天
能用起来的感觉真好
写在最后吧
做一件事应该是目标导向的,摒弃路径依赖的惰性思维,
就像红军长征,目标是确定的,道路是摸索的,逢山开路,遇水架桥,所以要发扬长征精神,不怕困难,勇往直前,道阻且长,行则将至。