记一次升级Flutter SDK失败的光辉历史

2022-06-10 14:06:08 浏览数 (1)

提示:本文内容颇为复杂,涉及到的疑难杂症也颇多。

一切源于一个简单的指令:flutter upgrade,然后开启了崩溃的黑色3小时。

刚打开项目,看到控制台的编译log提示Flutter SDK可以更新,行吧,那就更新吧,想着应该也是一个很简单的事情,因为我Android Studio也是经常更新的。

ok,编译结束,Terminal中直接执行flutter upgrade,因为之前也在官方文档中看到过升级 Flutter的介绍,内容不多,以为不复杂呢,结果这一执行直接掉进了无底的深渊。。

对插件下手

执行之后显示如下:

代码语言:javascript复制
D:FlutterProjectswanandroid_flutter>flutter upgrade
Checking Dart SDK version...
Downloading Dart SDK from Flutter engine 52c7a1e849a170be4b2b2fe34142ca2c0a6fea1f...
Downloading the Dart SDK using the BITS service failed, retrying with WebRequest...
Invoke-WebRequest : 请求被中止: 未能创建 SSL/TLS 安全通道。
所在位置 D:flutterflutter_windows_v1.2.1-stableflutterbininternalupdate_dart_sdk.ps1:62 字符: 5
      Invoke-WebRequest -Uri $dartSdkUrl -OutFile $dartSdkZip
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest],WebException
      FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
 
Error: Unable to update Dart SDK. Retrying...

网上搜了一会,根本没结果,但是我此刻也依然没当回事,并开启了一些骚操作。。

上面看到要升级Dart的sdk,因为dart的sdk是包含在flutter中的,在as在装flutter插件的时候还提示要装dart插件,

所以我直接从插件plugin下手了。

  • 卸载dart插件然后重启,卸载flutter插件然后重启。
  • 安装dart插件然后重启,安装flutter插件然后重启。

但是编译还是跑不起来,报什么错忘了,继续骚操作。。

对SDK下手

既然插件不行,行吧,那就直接手动升级sdk吧,此刻心态依然乐观,说来也是心大。

然后跑去github看了一下版本

纳尼,一天一个版本??? 这也太假了吧,我只要正式版就行啊。

然后又跑去官网看看:

嗯,这还差不多,我上个版本就是 1.2.1的,最新1.5.4的,那行吧,下载下来

  • 解压
  • 删掉1.2.1的版本
  • 改环境变量
  • 重启AS

emmmm 还是不行,且文件全部报错,开始有一点慌了。。

然后想起来项目中的路径可能还没改呢,然后在设置中把flutter sdk路径改成1.5.4的,感觉应该可以了

改好之后,满怀着期待重新编译,依然不行,此刻心态已经有点崩了,现在是退不能退 进不能进了。

尝试一下invalidate and restart,emmm 也不行

报错如下:

代码语言:javascript复制
Warning! This package referenced a Flutter repository via the .packages file that is no longer available. The repository from which the 'flutter' tool is currently executing will be used instead.
  running Flutter tool: D:flutterflutter_windows_v1.5.4-hotfix.2-stableflutter
  previous reference  : D:flutterflutter_windows_v1.2.1-stableflutter
This can happen if you deleted or moved your copy of the Flutter repository, or if it was on a volume that is no longer mounted or has been mounted at a different location. Please check your system path to verify that you are running the expected version (run 'flutter --version' to see which flutter is on your path).

嗯,我也知道两次版本不对,可是在哪改、怎么改呢。

对项目配置下手

我开始在项目中找有没有编译时类似build产生的文件,最后在根目录的.package文件中发现还是1.2.1的版本的

代码语言:javascript复制
# Generated by pub on 2019-05-28 10:50:34.749388.
async:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/async-2.0.8/lib/
boolean_selector:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/boolean_selector-1.0.4/lib/
charcode:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/charcode-1.1.2/lib/
collection:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/collection-1.14.11/lib/
cookie_jar:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/cookie_jar-1.0.0/lib/
cupertino_icons:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/cupertino_icons-0.1.2/lib/
dio:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/dio-2.1.3/lib/
flutter:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/packages/flutter/lib/
flutter_page_indicator:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/flutter_page_indicator-0.0.3/lib/
flutter_swiper:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/flutter_swiper-1.1.6/lib/
flutter_test:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/packages/flutter_test/lib/
flutter_webview_plugin:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/flutter_webview_plugin-0.3.5/lib/
fluttertoast:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/fluttertoast-3.0.4/lib/
matcher:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/matcher-0.12.3 1/lib/
meta:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/meta-1.1.6/lib/
path:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/path-1.6.2/lib/
pedantic:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/pedantic-1.4.0/lib/
quiver:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/quiver-2.0.1/lib/
sky_engine:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/bin/cache/pkg/sky_engine/lib/
source_span:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/source_span-1.5.4/lib/
stack_trace:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/stack_trace-1.9.3/lib/
stream_channel:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/stream_channel-1.6.8/lib/
string_scanner:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/string_scanner-1.0.4/lib/
term_glyph:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/term_glyph-1.1.0/lib/
test_api:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/test_api-0.2.2/lib/
transformer_page_view:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/transformer_page_view-0.1.6/lib/
typed_data:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/typed_data-1.1.6/lib/
vector_math:file:///D:/flutter/flutter_windows_v1.2.1-stable/flutter/.pub-cache/hosted/dart-pub.mirrors.sjtug.sjtu.edu.cn%47/vector_math-2.0.8/lib/
wanandroid_flutter:lib/

文件备份一下然后直接删掉,看看会不会编译生成,结果没有

那行吧,直接把路径替换了

天呐,依然不行,搞这个的时间早都超出预算了,心态已经崩了,只能硬着头皮上了。

只能在项目设置中尝试了。

打开Project Structure,果然他丫的还是有问题,但是看到了黎明的曙光。

  • 1,还是上面的问题。
  • 2,果然还是有一个路径没有改
  • 3,kotlin的直接忽略

先改掉2的路径问题

把1.2.1的版本路径换成1.5.4的路径即可。

但是1要fix的话提示我全部移除,那行吧,试试。

编译一下还是不行,此刻已然是生无可恋了。

因为之前打开了pubspec.yaml文件查看是不是有配置什么的没改,然后随手点了下packages get,结果OK了!!!

复盘

因为是手动升级的flutter SDK,所以项目中除了自带的库以外还有第三方的库,都还是原来的路径,在把全部路径修改完之后,需要packages get 重新下载到新版本的路径中去才能引用。

之前也尝试过packages upgrade,但是等了半天没反应,也没在任务管理中看到下载,所以就没当回事。。

访问国外网站这种小事就不提了。。

期间也遇到

代码语言:javascript复制
Waiting for another flutter command to release the startup lock...

解决办法:

  • 打开任务管理器,结束掉Android StudioDart.exe
  • 删除flutterbincache目录下的lockfile文件,然后重启AS即可

本文旨为flutter upgrade 升级flutter失败之后手动升级的记录,没准你一下就成功了。。

心累。。

Flutter 环境配置:https://cloud.tencent.com/developer/article/2019851

官方文档:https://flutter.dev/

0 人点赞