为什么Flutter应用在iOS模拟器正常运行,iPhone真机启动黑屏?
问题描述
应用可在iPhone 12(iOS 14.5)模拟器上正常运行,在搭载iOS 14.7.1的iPhone 11 Pro Max真机上运行时仅显示黑屏。
使用的Xcode版本为12.5.1。
Xcode运行输出日志
2021-09-16 18:48:00.155232+0300 Runner[2396:1009680] Metal API Validation Enabled 2021-09-16 18:48:00.244991+0300 Runner[2396:1009680] Could not load the "LaunchImage" image referenced from a nib in the bundle with identifier "xxx.yyy.zzz" 2021-09-16 18:48:00.353909+0300 Runner[2396:1009946] [VERBOSE-2:shell.cc(93)] Dart Error: Can't load Kernel binary: Invalid kernel binary format version. 2021-09-16 18:48:00.354015+0300 Runner[2396:1009946] [VERBOSE-2:dart_isolate.cc(170)] Could not prepare isolate. 2021-09-16 18:48:00.354185+0300 Runner[2396:1009946] [VERBOSE-2:runtime_controller.cc(382)] Could not create root isolate. 2021-09-16 18:48:00.354213+0300 Runner[2396:1009946] [VERBOSE-2:shell.cc(576)] Could not launch engine with configuration. 2021-09-16 18:48:00.367242+0300 Runner[2396:1009960] flutter: Observatory listening on http://127.0.0.1:54273/PrvtvZOQ8Wc=/
Flutter doctor检测结果
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5.2 20G95 darwin-x64, locale ru-BY) [✗] Android toolchain - develop for Android devices ✗ Unable to locate Android SDK. 安装Android Studio后首次启动会引导安装Android SDK相关组件。 如果Android SDK安装在自定义路径,可执行flutter config --android-sdk更新对应路径。 [✓] Xcode - develop for iOS and macOS [✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. [!] Android Studio (not installed) [✓] Connected device (2 available)
解决方案
按以下步骤操作即可解决问题:
- 执行命令清除Flutter本地缓存:
rm -rf ~/flutter/bin/cache - 直接从终端而非IDE执行运行命令:
flutter run,运行过程中Flutter会自动补全下载缺失的文件
内容的提问来源于stack exchange,提问作者engong
相关产品推荐
相关产品推荐

