在 iPhone 模拟器上运行的颤振卡在“Xcode 构建完成”上。 (它在android模拟器中运行良好)

Posted

技术标签:

【中文标题】在 iPhone 模拟器上运行的颤振卡在“Xcode 构建完成”上。 (它在android模拟器中运行良好)【英文标题】:flutter run on iPhone simulator stucks on 'Xcode build done'. (it runs well in android emulator) 【发布时间】:2021-12-22 18:03:12 【问题描述】:

问题

您好,我在 iPhone 模拟器上运行 Flutter 应用时遇到了困难。它停留在“Xcode build done”上。 顺便说一句,它在 android 模拟器上运行得很好。

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

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

附言我还在flutter github上开了一个issue:https://github.com/flutter/flutter/issues/93361

以下是详细信息:重现和记录的步骤。

复制步骤

操作系统:macOS Big Sur 11.6,连接到我的 iPhone 11 pro (ios 15.1) 的 USB 网络(热点)。

    克隆 https://github.com/kws1207/friendship/tree/main/where_to_eat 并打开项目。 运行模拟器,打开 iPhone 12 Pro Max、iOS 14.4。 执行flutter run。 选择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 的结果太长,无法在此处发布,已上传至: 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 构建。

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

【问题讨论】:

【参考方案1】:

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

【讨论】:

您好,感谢您的评论。目前我正在努力解决一个错误:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“在捆绑包 NSBundle 中找不到名为“Main”的情节提要。你能帮帮我吗? ***.com/questions/19240054/… 由于该链接是关于实际 iOS 设备的,因此似乎并非如此。【参考方案2】:

您需要将 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)
  

【讨论】:

它产生两个错误。 /Users/kws/Onedrive/projects/friendship/where_to_eat/ios/Runner/AppDelegate.s wift:12:8: 错误:如果 FirebaseApp.app() == nil /Users/kws/ 在范围内找不到“FirebaseApp” Onedrive/projects/friendship/where_to_eat/ios/Runner/AppDelegate.s wift:13:9: error: cannot find 'FirebaseApp' in scope FirebaseApp.configure() // 需要添加这个 你不是在顶部添加了这一行吗? “导入 Firebase” 我已经添加了完整的代码。 "import Firebase" 丢失。然而,问题并没有解决。我正在努力解决错误 [由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“在捆绑包 NSBundle 中找不到名为“Main”的情节提要]。谢谢。 添加后请使用flutter clean、flutter pub get和flutter run命令检查或关闭xcode重新打开。【参考方案3】:

请在 Xcode 的 buildSettings 中为 iOS 应用尝试这个添加新用户定义

EXTRA_FRONT_END_OPTIONS,值为--no-sound-null-safety

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

【讨论】:

【参考方案4】:

问题是我删除了“复制捆绑资源”中的所有组件。我在上面添加了 Main.storyboard,应用运行良好。

【讨论】:

以上是关于在 iPhone 模拟器上运行的颤振卡在“Xcode 构建完成”上。 (它在android模拟器中运行良好)的主要内容,如果未能解决你的问题,请参考以下文章

卡在颤振 gradle 构建

如何获取 iPhone 应用程序的崩溃报告

无法在物理 Apple 设备上运行颤振应用程序

我在 android studio 中运行我的颤振项目并尝试使用 iPhone 12 模拟器,但 Xcode 构建每次都失败

设置颤振时卡在dart sdk下载

在物理 iPhone 上运行颤振开发的应用程序时出错