解决 flutter Could not start Dart VM service HTTP server

7 min read
flutter: Could not start Dart VM service HTTP server:
SocketException: Failed to create server socket (OS Error: Operation not permitted, errno = 1), address = 127.0.0.1, port = 0
#0      _NativeSocket.bind (dart:io-patch/socket_patch.dart:996:7)
<asynchronous suspension>
#1      Server.startup.startServer (dart:vmservice_io/vmservice_server.dart:424:19)
<asynchronous suspension>
#2      Server.startup (dart:vmservice_io/vmservice_server.dart:443:11)
<asynchronous suspension>

修改 macos/Runner/DebugProfile.entitlements

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.security.app-sandbox</key>
	<true/>
	<key>com.apple.security.cs.allow-jit</key>
	<false/>
	<key>com.apple.security.network.client</key>
	<true/>
	<key>com.apple.security.network.server</key>
	<true/>
	<key>com.apple.security.temporary-exception.mach-register.global-name</key>
	<string>com.apple.screencapture.interactive</string>
</dict>
</plist>