请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

重载了这个插件就无法启动了

按照课程,我添加了shared_preferences这个插件,然后flutter run重新编译的时候就报错了。好像是什么东西超时,无法下载。

https://cdn.jsdelivr.net/cocoa/Specs/4/2/c/FlutterMacOS/3.16.0/FlutterMacOS.podspec.json
      CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/4/2/c/FlutterMacOS/1.12.1303/FlutterMacOS.podspec.json Response:
      Timeout was reached, retries: 4
      CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/4/2/c/FlutterMacOS/1.17.0/FlutterMacOS.podspec.json Response:
      Timeout was reached, retries: 4
      CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/4/2/c/FlutterMacOS/1.22.4/FlutterMacOS.podspec.json Response:
      Timeout was reached, retries: 4
      CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/4/2/c/FlutterMacOS/1.9.102/FlutterMacOS.podspec.json Response:
      Timeout was reached, retries: 4
      CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/4/2/c/FlutterMacOS/2.0.0/FlutterMacOS.podspec.json Response:
      Timeout was reached, retries: 4
      CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/4/2/c/FlutterMacOS/2.10.2/FlutterMacOS.podspec.json Response:
      Timeout was reached, retries: 4
      CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/4/2/c/FlutterMacOS/2.2.2/FlutterMacOS.podspec.json Response:
      Timeout was reached, retries: 4
      CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/4/2/c/FlutterMacOS/2.5/FlutterMacOS.podspec.json Response:
      Timeout was reached, retries: 4
      CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/4/2/c/FlutterMacOS/3.0.0/FlutterMacOS.podspec.json Response:
      Timeout was reached, retries: 4
      CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/4/2/c/FlutterMacOS/3.13.0/FlutterMacOS.podspec.json Response:

正在回答 回答被采纳积分+3

1回答

CrazyCodeBoy 2024-11-13 22:33:34
这个问题通常是因为网络连接问题导致无法从 CDN 下载 FlutterMacOS 的依赖。以下是一些解决方法,您可以尝试来解决此问题:

解决方法

1. 使用代理

如果您可以访问代理服务器或 VPN,可以尝试使用它来提升网络连接速度,避免请求超时。

2. 修改 CocoaPods 源

您可以将 CocoaPods 的源从 cdn.jsdelivr.net 切换到 https://gems.ruby-china.com/,这是国内的镜像源,通常会更快一些。

在终端中执行以下命令:

pod repo remove trunk
pod repo add trunk https://gems.ruby-china.com/

然后再次尝试运行:

flutter clean
flutter pub get
flutter run

3. 使用 pod install 并禁用 CDN

可以在项目的 ios 文件夹中手动运行 pod install 并禁用 CDN 使用,从而直接从 CocoaPods 的源拉取依赖。

执行以下命令:

cd ios
pod install --repo-update

4. 更新 Flutter 和 CocoaPods

确保您使用的是最新版本的 Flutter 和 CocoaPods,因为新版本可能会修复一些网络超时问题。

升级 Flutter:

flutter upgrade

升级 CocoaPods:

sudo gem install cocoapods

5. 检查网络连接

如果您在公司网络环境中运行,可能存在防火墙限制,导致请求被阻断。您可以尝试切换到其他网络,比如家庭网络或移动热点,再次运行命令。

6. 使用 flutter pub get 后重试

如果您的问题出现在 flutter run 的时候,可以尝试先运行:

flutter pub get
flutter clean
flutter run

以上方法中,国内用户通常可以通过设置镜像源来解决此类超时问题。试试这些方法,看看是否能解决您的问题。

0 回复 有任何疑惑可以回复我~
  • 提问者 前世定今生 #1
    按照你的命令修改国内镜像会报这个异常
    [!] Repo name `trunk` is reserved for CocoaPods' main spec repo accessed via CDN.
    
    查了一下,好像新版本默认这个trunk使用的几是官方的cdn
    回复 有任何疑惑可以回复我~ 2024-11-13 22:52:17
  • 提问者 前世定今生 #2
    老师,我网上找了别的办法,如果有其他同学遇到可以参照我这个方法,在ios下Podfile文件(没有则pod init生成)下,第一行增加了一个镜像
    source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
    
    然后就可以了。之前那个报错的问题也莫名其妙的就好了。
    回复 有任何疑惑可以回复我~ 2024-11-13 23:03:19
  • CrazyCodeBoy 回复 提问者 前世定今生 #3
    嗯,应该还是镜像的问题
    回复 有任何疑惑可以回复我~ 2024-11-14 08:53:48
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信