在iOS模拟器中启动Flutter应用程序

l2osamch  于 2023-05-19  发布在  Flutter
关注(0)|答案(3)|浏览(255)

我在iOS模拟器上启动Flutter应用程序时遇到问题。这个问题似乎与本地主机连接等有关,从下面的错误输出判断,但我无法找到如何修复它。
我运行的是MacOS Catalina 版本10.15.6(19G73)。iOS模拟器版本11.6(921.9.1)。VSCode是我的IDE。
该应用程序在Android模拟器上启动并运行良好。
下面是VSCode Terminal的错误输出:

Launching lib/main.dart on iPhone SE (2nd generation) in debug mode...
Running Xcode build...                                                  
 └─Compiling, linking and signing...                         6.7s
Xcode build done.                                           16.7s
Connecting to the VM Service is taking longer than expected...
Still attempting to connect to the VM Service...
If you do NOT see the Flutter application running, it might have crashed. The device logs (e.g. from adb or XCode) might have more details.
If you do see the Flutter application running on the device, try re-running with --host-vmservice-port to use a specific port known to be available.
Exception attempting to connect to the VM Service: SocketException: OS Error: Connection refused, errno = 61, address = 127.0.0.1, port = 51838
This was attempt #50. Will retry in 0:00:01.600000.
Exception attempting to connect to the VM Service: SocketException: OS Error: Connection refused, errno = 61, address = 127.0.0.1, port = 51970
This was attempt #100. Will retry in 0:00:01.600000.
Exception attempting to connect to the VM Service: SocketException: OS Error: Connection refused, errno = 61, address = 127.0.0.1, port = 52119
This was attempt #150. Will retry in 0:00:01.600000.
Exception attempting to connect to the VM Service: SocketException: OS Error: Connection refused, errno = 61, address = 127.0.0.1, port = 52347
This was attempt #200. Will retry in 0:00:01.600000.
^C%
bxpogfeg

bxpogfeg1#

因为Firebase,我也遇到了同样的问题。我通过反转AppDelegate.swift文件中的两行来修复我的问题:

FirebaseApp.configure() // Should be first
GeneratedPluginRegistrant.register(with: self) // Should be second

我的非工作文件是这个

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) // <- Don't do this
    FirebaseApp.configure()   // <- Don't do this
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

我的工作档案是:

import UIKit
import Flutter
import Firebase

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

prdp8dxp2#

我也有同样的问题,无法在iOS模拟器中正常运行应用程序,它总是显示一个白色的空白页面。
我找到了这个https://github.com/flutter/flutter/issues/71395,这个链接告诉我们如果你的Flutter版本低于2.0.0,那么你会在master分支得到正确的按摩。
所以我用以下步骤解决了这个问题:
1.我用的是Brew

brew info flutter

1.将Flutter的git分支切换到master

cd <flutter path>
git checkout -b master origin/master

1.发现问题

flutter doctor -v

这说明我的问题是
[!]代理配置
·设置HTTP_PROXY
!NO_PROXY未设置
所以我需要设置thd NO_PROXY配置,https://github.com/flutter/flutter/issues/24854,这个链接告诉我如何配置它。
现在我可以在iOS模拟器中正常运行应用了。

slsn1g29

slsn1g293#

晚到党,但为将来的参考-有时你必须添加额外的出口信息.zshrc或.bashrc文件由于代理问题:

export HTTP_PROXY=http://127.0.0.1:1087
export HTTPS_PROXY=http://127.0.0.1:1087
export NO_PROXY=localhost,127.0.0.1,LOCALHOST

此解决方案允许您在模拟器或连接的设备上运行应用程序。
原作者及解决方案:https://github.com/flutter/flutter/issues/24854#issuecomment-525105693

相关问题