【问题标题】:Flutter App doesn't run on iOS Simulator, flutter build ios worksFlutter App 无法在 iOS 模拟器上运行,flutter build ios 可以工作
【发布时间】:2022-02-16 19:59:20
【问题描述】:

我正在尝试在我的 Apple Silicon Mac 上的 iOS 模拟器中运行我的颤振应用程序,该应用程序使用 firebase,但它无法正常工作。 flutter run 引发以下错误,但 flutter build ios 可以正常工作。有没有人有类似的问题,可以帮助我?我已经尝试了以下事情(不幸的是没有成功):

https://github.com/FirebaseExtended/flutterfire/issues/1979#issuecomment-590173571

https://github.com/FirebaseExtended/flutterfire/issues/1944

Flutter on IOS: fatal error: module 'cloud_firestore' not found

https://bleepcoder.com/flutterfire/562990746/cloud-firestore-fatal-error-module-cloud-firestore-not-found

这是我的终端输出(flutter run):

flutter run
Multiple devices found:
sdk gphone arm64 (mobile)  • emulator-5554                        • android-arm64 • Android 11 (API 30) (emulator)
iPhone 13 Pro Max (mobile) • ABCD • ios           • com.apple.CoreSimulator.SimRuntime.iOS-15-2 (simulator)
[1]: sdk gphone arm64 (emulator-5554)
[2]: iPhone 13 Pro Max (ABCD)
Please choose one (To quit, press "q/Q"): 2
Launching lib/main.dart on iPhone 13 Pro Max in debug mode...
Running pod install...                                              8,7s
Running Xcode build...                                                  
 └─Compiling, linking and signing...                      2.778ms
Xcode build done.                                           18,1s
Failed to build iOS app
Error output from Xcode build:
↳
    objc[10675]: Class AMSupportURLConnectionDelegate is implemented in both /usr/lib/libamsupport.dylib (0x2023af678) and
    /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x1042402c8). One of the two will be used. Which one is
    undefined.
    objc[10675]: Class AMSupportURLSession is implemented in both /usr/lib/libamsupport.dylib (0x2023af6c8) and
    /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x104240318). One of the two will be used. Which one is
    undefined.
    ** BUILD FAILED **


Xcode's output:
↳
    /Users/XXXX/Development/recipe_vault_fl/ios/Pods/AppAuth/Source/AppAuth/iOS/OIDExternalUserAgentIOSCustomBrowser.m:148:42: warning: 'openURL:' is
    deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]
          [[UIApplication sharedApplication] openURL:_appStoreURL];
                                             ^~~~~~~
                                             openURL:options:completionHandler:
    In module 'UIKit' imported from /Users/XXXX/Development/recipe_vault_fl/ios/Pods/Target Support Files/AppAuth/AppAuth-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/System/Library/Frameworks/UIKit.fram
    ework/Headers/UIApplication.h:124:1: note: 'openURL:' has been explicitly marked deprecated here
    - (BOOL)openURL:(NSURL*)url API_DEPRECATED_WITH_REPLACEMENT("openURL:options:completionHandler:", ios(2.0, 10.0)) NS_EXTENSION_UNAVAILABLE_IOS("");
    ^
    /Users/XXXX/Development/recipe_vault_fl/ios/Pods/AppAuth/Source/AppAuth/iOS/OIDExternalUserAgentIOSCustomBrowser.m:156:61: warning: 'openURL:' is
    deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]
      BOOL openedInBrowser = [[UIApplication sharedApplication] openURL:requestURL];
                                                                ^~~~~~~
                                                                openURL:options:completionHandler:
    In module 'UIKit' imported from /Users/XXXX/Development/recipe_vault_fl/ios/Pods/Target Support Files/AppAuth/AppAuth-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/System/Library/Frameworks/UIKit.fram
    ework/Headers/UIApplication.h:124:1: note: 'openURL:' has been explicitly marked deprecated here
    - (BOOL)openURL:(NSURL*)url API_DEPRECATED_WITH_REPLACEMENT("openURL:options:completionHandler:", ios(2.0, 10.0)) NS_EXTENSION_UNAVAILABLE_IOS("");
    ^
    2 warnings generated.
    /Users/XXXX/Development/recipe_vault_fl/ios/Pods/AppAuth/Source/AppAuth/iOS/OIDExternalUserAgentIOS.m:168:58: warning: 'openURL:' is deprecated: first
    deprecated in iOS 10.0 [-Wdeprecated-declarations]
        openedUserAgent = [[UIApplication sharedApplication] openURL:requestURL];
                                                             ^~~~~~~
                                                             openURL:options:completionHandler:
    In module 'UIKit' imported from /Users/XXXX/Development/recipe_vault_fl/ios/Pods/Target Support Files/AppAuth/AppAuth-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/System/Library/Frameworks/UIKit.fram
    ework/Headers/UIApplication.h:124:1: note: 'openURL:' has been explicitly marked deprecated here
    - (BOOL)openURL:(NSURL*)url API_DEPRECATED_WITH_REPLACEMENT("openURL:options:completionHandler:", ios(2.0, 10.0)) NS_EXTENSION_UNAVAILABLE_IOS("");
    ^
    1 warning generated.
    /Users/XXXX/Development/recipe_vault_fl/ios/Runner/GeneratedPluginRegistrant.m:12:9: fatal error: module 'cloud_firestore' not found
    @import cloud_firestore;
     ~~~~~~~^~~~~~~~~~~~~~~
    1 error generated.
    note: Using new build system
    note: Planning
    note: Build preparation complete
    note: Building targets in dependency order

Could not build the application for the simulator.
Error launching application on iPhone 13 Pro Max.

这是我的终端输出(flutter build ios):

flutter build ios
Running "flutter pub get" in recipe_vault_fl...                  1.910ms
Building XX.XXXXXXXX.XXXXXXXXXXXXX for device (ios-release)...
Automatically signing iOS for device deployment using specified development team in Xcode project: XXXXXXXXXX
Running pod install...                                             11,2s
Running Xcode build...                                                  
 └─Compiling, linking and signing...                         9,1s
Xcode build done.                                           134,6s
Built /Users/XXXX/Development/recipe_vault_fl/build/ios/iphoneos/Runner.app.

编辑: 这是我的 AppDelegate.swift 文件:

import UIKit
import Flutter

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

我不知道是否有必要,但这也是我的 pubspec.yaml 文件:

name: recipe_vault_fl
description: Manage your recipes and grocery lists easily.

# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.12.0 <3.0.0"

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
  cloud_firestore: ^3.1.8
  cupertino_icons: ^1.0.2
  dropdown_button2: ^1.1.1
  email_validator: ^2.0.1
  equatable: ^2.0.3
  firebase_auth: ^3.3.7
  firebase_core: ^1.12.0
  flutter:
    sdk: flutter
  flutter_bloc: ^8.0.1
  flutter_material_pickers: ^3.1.2
  flutter_reorderable_list: ^1.1.0
  flutter_slidable: ^1.1.0
  flutterfire_ui: ^0.3.4
  page_transition: ^2.0.4
  uuid: ^3.0.5

dev_dependencies:
  flutter_lints: ^1.0.0
  flutter_test:
    sdk: flutter

【问题讨论】:

    标签: ios xcode firebase flutter cocoapods


    【解决方案1】:

    尝试这些步骤;

    cd ios

    吊舱解体

    吊舱安装

    cd ..

    颤抖干净

    颤振构建 ios

    颤动运行

    如果它不起作用,请分享您的 ios/Runner/AppDelegate.swift 文件

    【讨论】:

    • 不幸的是这些步骤没有帮助,我仍然得到同样的错误。但是我现在已经更新了问题以包含 AppDelegate 和 pubspec 文件。我希望他们有所帮助。感谢您的帮助。
    【解决方案2】:

    首先尝试运行您的 Xcode,并确保它是最新的。在 Xcode 上打开 {flutter_project}/ios 构建,然后尝试从那里在模拟器上运行 iOS 项目。

    如果您仍然遇到问题,可以在终端上运行此命令。这通常可以解决在模拟器上运行 Flutter iOS 构建的问题,并且应该设置活动开发者目录的路径。

    sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
    

    【讨论】:

    • 不幸的是,该解决方案对我也不起作用。不过还是谢谢你的帮助
    猜你喜欢
    • 2021-02-07
    • 2022-09-28
    • 2021-06-27
    • 2021-12-20
    • 2020-09-27
    • 1970-01-01
    • 2018-10-24
    • 2021-06-07
    • 2021-11-01
    相关资源
    最近更新 更多