flutter运行后白屏卡住无法启动 / Flutter app stuck at installing with white screen

问题背景和症状:

很久之前尝试配置过一次flutter环境,体验了一下。很久没用了,最近有了兴趣,又想看下flutter有什么变化。

  1. 按照官方教程装好了flutter环境,运行flutter doctor无异常项
  2. 下载了一个demo app工程,点击运行(ios),编译完成后,安装到了模拟器上,app自动打开了,但是卡在白屏。
  3. 杀死app后,手动打开能正常进入。

尝试和解决

  1. 尝试安装到android模拟器上,也是同样的症状❌
  2. 尝试运行flutter clean清除缓存,问题没有解决❌
  3. 尝试运行flutter pub cache clean清除依赖缓存,问题没有解决❌
  4. 运行flutter run -v查看输出信息,发现最后是卡在Connecting to service protocol:http://127.0.0.1:57071/0dqLN-ZPpFk=/这一行了,怀疑是57071这个端口有问题,运行lsof -i:57071查看占用这个端口的进程的pid,然后运行kill <pid>杀掉这个进程。再次运行发现还是不行,并且发现这个service每次都会换个端口,问题应该不是在这。❌
  5. 忽然留意到每次运行flutter命令的时候,第一句都是Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!,想起来以前因为网络环境不好,换过源,不会是这个源有问题吧,于是赶紧查看~/.zshrc文件,果然在里面发现了这个配置
    1
    2
    3
    export PUB_HOSTED_URL=https://pub.flutter-io.cn
    export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
    export FLUTTER_GIT_URL=https://gitee.com/mirrors/Flutter.g
    删掉这几行,然后重启vscode,再次运行,问题就解决了。回顾一下应该就是这个源的内容不够新甚至不正确导致的!✅

总结,不能轻易相信第三方源,配置好网络环境永远是配置环境的第一步

stackoverflow上查了半天,没有一个将问题指向源的,在此做下记录,希望能帮助到遇到同样问题的人。♥️

如果上面没有解决你的问题,可以参考:

https://stackoverflow.com/questions/75665760/flutter-run-stuck-on-launching

https://stackoverflow.com/questions/68698437/flutter-app-stuck-at-installing-with-white-screen

flutter运行后白屏卡住无法启动 / Flutter app stuck at installing with white screen

https://chewenkai.github.io/uncategorized/flutter运行后白屏卡住无法启动-flutter-app-stuck-at-installing-with-white-screen/

Author

calvinche

Posted on

2024-04-13

Licensed under

CC BY-NC-SA 4.0

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×