I’ve faced the flutter error “Connecting to the VM service taking longer than expected” several times during developing flutter apps. This seems to be a common error and more information can be obtained from the Xcode logs about the exact error message.
This is how the error looks :
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
Here are few things that helped address the issue :
- Make sure you run flutter
pub cache repair
or
flutter clean
before running
flutter run
just to make sure you get all the dependencies to the latest before running app
- In AppDelegate, make sure the following statements are in correct order :
1 – FirebaseApp.configure()
2 – GeneratedPluginRegistrant.register(with: self)Here is how the file should look like :
import UIKit import Flutter import Firebase @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { FirebaseApp.configure() // <- First this GeneratedPluginRegistrant.register(with: self) // <- Then this return super.application(application, didFinishLaunchingWithOptions: launchOptions) } }
- check Automatically manage signing in Xcode
Xcode project ( TestProject ) —> one of the TARGETS ( TestProject ) —> Signing & Capabilities —> Signing -> Automatically Manage Signing
- Ensure the script is mentioned this way in Runner -> Build Phases – > Thin Binary
Hope this helps fix this problem for you. If you have found other causes or solutions, please add them in the comment section so that others can refer the same.
© 2020, https:. All rights reserved. On republishing this post, you must provide link to original post