Flutter ios“无法为模拟器构建应用程序。”

13

我有一个用Flutter编写的Android应用程序。 现在我正在尝试制作它的iOS版本,但是遇到了错误。我尝试运行一个空白的Flutter项目,它可以成功运行。

pod install没有错误

在尝试使用flutter run命令时,我遇到了以下错误。

我的Podfile文件如下所示。

我该如何解决这个问题?

Flutter运行输出:

    Xcode's output:
↳
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-2.0.9/ios/Classes/FlutterWebView.m:395:23:
    warning: 'requiresUserActionForMediaPlayback' is deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]
            configuration.requiresUserActionForMediaPlayback = true;
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          mediaTypesRequiringUserActionForPlayback
    In module 'WebKit' imported from
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-2.0.9/ios/Classes/FlutterWebView.h:6:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/System/Library/Framew
    orks/WebKit.framework/Headers/WKWebViewConfiguration.h:213:28: note: 'requiresUserActionForMediaPlayback' has been explicitly marked
    deprecated here
    @property (nonatomic) BOOL requiresUserActionForMediaPlayback API_DEPRECATED_WITH_REPLACEMENT("mediaTypesRequiringUserActionForPlayback",
    ios(9.0, 10.0));
                               ^
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-2.0.9/ios/Classes/FlutterWebView.m:407:23:
    warning: 'requiresUserActionForMediaPlayback' is deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]
            configuration.requiresUserActionForMediaPlayback = false;
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          mediaTypesRequiringUserActionForPlayback
    In module 'WebKit' imported from
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-2.0.9/ios/Classes/FlutterWebView.h:6:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/System/Library/Framew
    orks/WebKit.framework/Headers/WKWebViewConfiguration.h:213:28: note: 'requiresUserActionForMediaPlayback' has been explicitly marked
    deprecated here
    @property (nonatomic) BOOL requiresUserActionForMediaPlayback API_DEPRECATED_WITH_REPLACEMENT("mediaTypesRequiringUserActionForPlayback",
    ios(9.0, 10.0));
                               ^
    2 warnings generated.
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/InAppBrowser/InAppBrow
    serWebViewController.swift:557:13: warning: setter for 'statusBarStyle' was deprecated in iOS 9.0: Use -[UIViewController
    preferredStatusBarStyle]
                UIApplication.shared.statusBarStyle = UIStatusBarStyle(rawValue: previousStatusBarStyle)!
                ^
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/SafariViewController/S
    afariBrowserOptions.swift:34:16: warning: unnecessary check for 'iOS'; enclosing scope ensures guard will always be true
                if #available(iOS 10.0, *) {
                   ^
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/SafariViewController/S
    afariBrowserOptions.swift:12:14: note: enclosing scope here
    public class SafariBrowserOptions: Options<SafariViewController> {
                 ^
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/SafariViewController/S
    afariViewController.swift:66:12: warning: unnecessary check for 'iOS'; enclosing scope ensures guard will always be true
            if #available(iOS 10.0, *) {
               ^
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/SafariViewController/S
    afariViewController.swift:12:14: note: enclosing scope here
    public class SafariViewController: SFSafariViewController, FlutterPlugin, SFSafariViewControllerDelegate {
                 ^
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/SafariViewController/S
    afariBrowserOptions.swift:34:16: warning: unnecessary check for 'iOS'; enclosing scope ensures guard will always be true
                if #available(iOS 10.0, *) {
                   ^
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/SafariViewController/S
    afariBrowserOptions.swift:12:14: note: enclosing scope here
    public class SafariBrowserOptions: Options<SafariViewController> {
                 ^
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/SafariViewController/S
    afariViewController.swift:66:12: warning: unnecessary check for 'iOS'; enclosing scope ensures guard will always be true
            if #available(iOS 10.0, *) {
               ^
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/SafariViewController/S
    afariViewController.swift:12:14: note: enclosing scope here
    public class SafariViewController: SFSafariViewController, FlutterPlugin, SFSafariViewControllerDelegate {
                 ^
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/Types/URLCredential.sw
    ift:14:25: warning: comparing non-optional value of type '[Any]' to 'nil' always returns true
            if certificates != nil {
               ~~~~~~~~~~~~ ^  ~~~
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/Util.swift:86:25:
    warning: 'spotlightSuggestion' was deprecated in iOS 10.0: renamed to 'WKDataDetectorTypes.lookupSuggestion'
                    return .spotlightSuggestion
                            ^
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/Util.swift:86:25:
    note: use 'WKDataDetectorTypes.lookupSuggestion' instead
                    return .spotlightSuggestion
                            ^~~~~~~~~~~~~~~~~~~
                            WKDataDetectorTypes.lookupSuggestion
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/Util.swift:121:31:
    warning: 'spotlightSuggestion' was deprecated in iOS 10.0: renamed to 'WKDataDetectorTypes.lookupSuggestion'
                if type.contains(.spotlightSuggestion) {
                                  ^
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/Util.swift:121:31:
    note: use 'WKDataDetectorTypes.lookupSuggestion' instead
                if type.contains(.spotlightSuggestion) {
                                  ^~~~~~~~~~~~~~~~~~~
                                  WKDataDetectorTypes.lookupSuggestion
    /usr/local/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/ios/Classes/Util.swift:216:21:
    warning: immutable value 'j' was never used; consider replacing with '_' or removing it
                    for j in ipv6.count...8 {
                        ^
                        _
    Undefined symbols for architecture x86_64:
      "_OBJC_CLASS_$_GULAppEnvironmentUtil", referenced from:
          objc-class-ref in FIRCLSApplication.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    Undefined symbols for architecture i386:
      "_OBJC_CLASS_$_GULAppEnvironmentUtil", referenced from:
          objc-class-ref in FIRCLSApplication.o
    ld: symbol(s) not found for architecture i386
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    Undefined symbols for architecture arm64:
      "_OBJC_CLASS_$_GULAppEnvironmentUtil", referenced from:
          objc-class-ref in FIRCLSApplication.o
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Analyzing workspace
    note: Constructing build description
    note: Build preparation complete
    warning: Stale file
    '/Users/emre/Desktop/freegamescodes/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/flutter_local_notifications.framework' is
    located outside of the allowed root paths.


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

我的 Pod 文件:

# Uncomment this line to define a global platform for your project
platform :ios, '10.0'

pod 'Firebase'
pod 'Firebase/Crashlytics'
pod 'Firebase/Analytics'
pod 'Firebase/Messaging'
pod 'Google-Mobile-Ads-SDK'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
     end
  end

有什么解决方案吗? - Jigar Fumakiya
你需要先在Flutter项目中定位到iOS文件夹,然后使用gem重新安装CocoaPods和ffi。 - Mouaz M Shahmeh
看起来这是Firebase的问题。你控制台日志中唯一重要的部分是Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_GULAppEnvironmentUtil", referenced from: objc-class-ref in FIRCLSApplication.o请参见Firebase问题#8137 - James Allen
5个回答

1

打开lib / ios文件夹,并删除以下内容:

  • Podfile
  • Podfile.lock
  • Pods文件夹
  • Runner.xcworkspace

然后运行flutter build ios

构建ios之后,运行open ios/Runner.xcworkspace/,然后在XCode中第一次运行项目,之后,一切都会正常工作。


0

先备份项目,然后删除ios文件夹并使用命令"flutter create .",别忘了点号。


0

flutter clean 然后进入 cd ios

然后重新启动 IDE ..


目前你的回答写得不够清晰。请 [编辑] 添加更多细节以帮助其他人理解它如何回答所提出的问题。你可以在 帮助中心 中找到更多有关如何撰写好答案的信息。 - Community

0

打开pubspec.yaml文件,

  • 点击pub_upgrade或输入flutter pub upgrade命令
  • 运行flutter clean指令,

打开lib/ios文件夹并删除其中的

Podfile.lock

并运行

pod install

在构建iOS文件后,运行Xcode项目,一切都会很好。


0

备份您的项目并尝试此命令:flutter clean && \ rm ios/Podfile ios/Podfile.lock pubspec.lock && \ rm -rf ios/Pods ios/Runner.xcworkspace && \ flutter run


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接