iPhone 上的 flutter 运行 模拟器卡在 'Xcode build done' 上。 (它 运行 在 android 模拟器中很好)

flutter run on iPhone simulator stucks on 'Xcode build done'. (it runs well in android emulator)

问题

您好,我在 iPhone 模拟器上 运行 我的 Flutter 应用程序时遇到困难。它停留在 'Xcode build done'。 顺便说一句,它在 Android 模拟器上运行良好。

这是我第一次在这里提问,所以如果需要更多信息或有不当之处,请告诉我。 任何形式的帮助(或评论)将不胜感激。谢谢。

尝试手动启动应用程序的视频: https://user-images.githubusercontent.com/60031762/141050073-648a9893-0e33-425e-9c9d-24966bf1be39.mov

p.s。我还在 flutter github 上开了一个问题:https://github.com/flutter/flutter/issues/93361

以下是详细信息:重现步骤和日志。

重现步骤

OS: macOS Big Sur 11.6, 连接到我的 iPhone 11 pro(iOS 15.1).[=28= 的 USB 网络(热点) ]

  1. 克隆 https://github.com/kws1207/friendship/tree/main/where_to_eat 并打开项目。
  2. 运行模拟器,打开iPhone12 Pro Max,iOS14.4.
  3. 执行flutter run.
  4. Select模拟器在2中打开

预期结果:

Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
Running Xcode build...                                                  
 └─Compiling, linking and signing...                         8.3s
Xcode build done.                                           268.6s
Installing and launching...
Flutter run key commands.
r Hot reload. 
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

Running with unsound null safety
For more information see
https://dart.dev/null-safety/unsound-null-safety

实际结果:

Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
Running Xcode build...                                                  
 └─Compiling, linking and signing...                         8.3s
Xcode build done.                                           268.6s
(it stucks here)

日志

flutter run --verbose 的结果太长 post,上传地址: https://drive.google.com/file/d/1DbiusrV3sNm3X03QAlDau3ztpqCBCw4S/view?usp=sharing

flutter analyze的结果:

Analyzing where_to_eat...                                               

   info • Name non-constant identifiers using lowerCamelCase • lib/domain/classes.dart:6:10 • non_constant_identifier_names
   info • Name non-constant identifiers using lowerCamelCase • lib/domain/classes.dart:7:10 • non_constant_identifier_names
   info • Name non-constant identifiers using lowerCamelCase • lib/domain/classes.dart:10:10 • non_constant_identifier_names
   info • Name non-constant identifiers using lowerCamelCase • lib/domain/classes.dart:15:13 • non_constant_identifier_names
   info • Name non-constant identifiers using lowerCamelCase • lib/domain/classes.dart:16:12 • non_constant_identifier_names
   info • Name non-constant identifiers using lowerCamelCase • lib/domain/classes.dart:18:12 • non_constant_identifier_names
   info • Don't import implementation files from another package • lib/screens/list_screen.dart:4:8 • implementation_imports
   info • The value of the field '_auth' isn't used • lib/screens/list_screen.dart:57:9 • unused_field
   info • 'await' applied to 'void', which is not a 'Future' • lib/screens/list_screen.dart:84:5 • await_only_futures
   info • 'await' applied to 'void', which is not a 'Future' • lib/screens/list_screen.dart:85:5 • await_only_futures
   info • 'await' applied to 'void', which is not a 'Future' • lib/screens/list_screen.dart:507:9 • await_only_futures
   info • This function has a return type of 'FutureOr<Response>', but doesn't end with a return statement • lib/screens/list_screen.dart:548:25 •
          missing_return
   info • This function has a return type of 'Widget', but doesn't end with a return statement • lib/screens/list_screen.dart:690:10 •
          missing_return
   info • This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final:
          RouletteScreen.labels • lib/screens/roulette_screen.dart:10:7 • must_be_immutable
   info • Unused import: 'package:http/http.dart' • lib/screens/select_screen.dart:2:8 • unused_import
   info • Duplicate import • lib/screens/select_screen.dart:8:8 • duplicate_import
   info • Don't import implementation files from another package • lib/screens/select_screen.dart:11:8 • implementation_imports
   info • The value of the field '_firestore' isn't used • lib/screens/select_screen.dart:30:9 • unused_field
   info • Don't explicitly initialize variables to null • lib/screens/select_screen.dart:34:11 • avoid_init_to_null
   info • The declaration '_showSignOutFailDialog' isn't referenced • lib/screens/select_screen.dart:96:8 • unused_element
   info • 'await' applied to 'void', which is not a 'Future' • lib/screens/select_screen.dart:180:11 • await_only_futures
warning • The parameter 'addressEng' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'addressType' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'apartment' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'bcode' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'bname' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'bnameEng' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'buildingCode' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'buildingName' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'jibunAddress' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'jibunAddressEng' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'postCode' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'query' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'roadAddress' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'roadAddressEng' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'roadname' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'roadnameCode' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'roadnameEng' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'sido' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'sidoEng' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'sigungu' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'sigunguCode' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'sigunguEng' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'userLanguageType' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
warning • The parameter 'userSelectedType' is required • lib/screens/select_screen.dart:182:23 • missing_required_param
   info • 'await' applied to 'void', which is not a 'Future' • lib/screens/select_screen.dart:272:5 • await_only_futures
   info • The value of the field '_firestore' isn't used • lib/screens/signin_screen.dart:27:9 • unused_field
   info • The value of the field '_userEmail' isn't used • lib/screens/signin_screen.dart:29:10 • unused_field
   info • The value of the field '_userPassword' isn't used • lib/screens/signin_screen.dart:29:22 • unused_field
   info • The stack trace variable 's' isn't used and can be removed • lib/screens/signin_screen.dart:315:27 • unused_catch_stack
   info • The value of the field '_firestore' isn't used • lib/screens/signup_screen.dart:22:9 • unused_field
   info • The value of the field '_userEmail' isn't used • lib/screens/signup_screen.dart:23:10 • unused_field
   info • The value of the field '_userPassword' isn't used • lib/screens/signup_screen.dart:23:22 • unused_field

53 issues found. (ran in 3.6s)

flutter doctor -v的结果:

[✓] Flutter (Channel stable, 2.5.3, on macOS 11.6 20G165 darwin-x64, locale ko-KR)
    • Flutter version 2.5.3 at /Applications/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (4 weeks ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/kws/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.11.2

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/google-chrome-unsafe)
    ! /Applications/Google Chrome.app/Contents/MacOS/google-chrome-unsafe is not executable.

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] IntelliJ IDEA Community Edition (version 2019.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 43.0.2
    • Dart plugin version 192.8052

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.28.0

[✓] Connected device (2 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554                        • android-x64 • Android 12 (API 31) (emulator)
    • iPhone 12 Pro Max (mobile)   • 0A68628E-A233-40C2-8B07-504F23A5FD81 • ios         • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)
    ! Error: Errors were encountered while preparing your device for development. Please check the Devices and Simulators Window.  (code -1)

! Doctor found issues in 1 category.

来自 Xcode 的输出:

libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main' in bundle NSBundle </Users/kws/Library/Developer/CoreSimulator/Devices/0A68628E-A233-40C2-8B07-504F23A5FD81/data/Containers/Bundle/Application/F06A8FF1-690C-4F28-BCCC-C045F422BA70/Runner.app> (loaded)'
terminating with uncaught exception of type NSException
CoreSimulator 732.18.6 - Device: iPhone 12 Pro Max (0A68628E-A233-40C2-8B07-504F23A5FD81) - Runtime: iOS 14.4 (18D46) - DeviceType: iPhone 12 Pro Max

请检查list_screen中的错误,行号548和690。删除Podfile.lock。 运行扑干净。然后运行flutter run。使用项目根目录中的 cd ios 导航到终端中的 ios 文件夹。 运行pod install。现在,一旦安装了 pods,打开 xcode 中的 xcworkspace 文件,您可能会看到一条警告,要求您升级 ios 的最低版本。允许它升级设置。现在 select 来自 xcode 的模拟器并点击播放。一旦它在 xcode 播放良好,您应该也可以直接从 Android 工作室 运行 它。

您需要将 firebase 配置初始化到 appdelegate.swift 文件中。

import UIKit
import Flutter
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    
    if FirebaseApp.app() == nil {
        FirebaseApp.configure()
    }
    
   // FirebaseApp.configure()
    
   return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

请在 Xcode 的 buildSettings 中为 iOS 应用尝试此操作 添加新用户定义

具有值 --no-sound-null-safety

的键 EXTRA_FRONT_END_OPTIONS

并清除派生数据并再次重建它,然后 运行 它。

问题是我删除了 'Copy Bundle Resources' 中的所有组件。我在上面添加了 Main.storyboard,应用程序运行正常。