Repository: flutter
Issue: flutter attach fails to discover Dart VM service on iOS Simulator in add2app setup
Labels: platform-ios,a: existing-apps,has reproducible steps,P2,team-ios,triaged-ios,found in release: 3.27,found in release: 3.28

I'm experiencing an issue where the `flutter attach` command fails to automatically discover the Dart VM service when running a Flutter module in an iOS Simulator. The command works correctly on a physical device, and I can manually connect using the `--debug-url` option with the Dart VM address.

### Steps to reproduce

1. Create a Flutter module using `flutter create -t module my_flutter_module`.
2. Create a new iOS app in Xcode and integrate the Flutter module following the [add-to-app documentation](https://docs.flutter.dev/add-to-app/ios/project-setup).
3. Run the iOS app on the iOS Simulator using Xcode.
4. Attempt to attach using `flutter attach` from the Flutter module directory.

### Expected results

The `flutter attach` command should automatically discover and connect to the Dart VM service running in the iOS Simulator.

### Actual results

The `flutter attach -v` gets stuck indefinitely with the message: "The Dart VM Service was not discovered after 30 seconds. This is taking much longer than expected..." (logs below)

### Code sample

https://github.com/MDemetrio/attach_add2app_reproduction


### Screenshots or Video

N/A

### Logs

<details open><summary>Logs</summary>

```console
my_flutter_module % flutter attach -v
[   +8 ms] executing: sw_vers -productName
[  +16 ms] Exit code 0 from: sw_vers -productName
[        ] macOS
[        ] executing: sw_vers -productVersion
[  +15 ms] Exit code 0 from: sw_vers -productVersion
[        ] 13.5.1
[        ] executing: sw_vers -buildVersion
[  +15 ms] Exit code 0 from: sw_vers -buildVersion
[        ] 22G90
[        ] executing: uname -m
[   +5 ms] Exit code 0 from: uname -m
[        ] x86_64
[   +5 ms] executing: sysctl hw.optional.arm64
[   +4 ms] Exit code 1 from: sysctl hw.optional.arm64
[        ] sysctl: unknown oid 'hw.optional.arm64'
[ +103 ms] executing: sysctl hw.optional.arm64
[   +7 ms] Exit code 1 from: sysctl hw.optional.arm64
[        ] sysctl: unknown oid 'hw.optional.arm64'
[        ] executing: xcrun xcodebuild -version
[ +251 ms] Exit code 0 from: xcrun xcodebuild -version
[        ] Xcode 15.2
           Build version 15C500b
[   +3 ms] executing: xcrun xcdevice list --timeout 5
[   +5 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'LegacyCanvasKitRemover' is not required, skipping update.
[   +2 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +51 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'LegacyCanvasKitRemover' is not required, skipping update.
[        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'PubDependencies' is not required, skipping update.
[  +54 ms] executing: /Users/matheus.demetrio/Library/Android/sdk/platform-tools/adb devices -l
[        ] executing: xcrun xcdevice list --timeout 2
[   +1 ms] xcrun simctl list devices booted iOS --json
[        ] executing: xcrun simctl list devices booted iOS --json
[   +2 ms] executing: xcrun simctl list devices booted
[ +416 ms] Exit code 0 from: xcrun simctl list devices booted
[        ] == Devices ==
           -- iOS 15.5 --
           -- iOS 16.4 --
           -- iOS 17.0 --
           -- iOS 17.0 --
           -- iOS 17.2 --
               iPhone 15 Pro Max (DA5276D1-579A-45FD-92CB-3C1AD5EB425A) (Booted)
[  +34 ms] List of devices attached
[ +401 ms] {
                      "devices" : {
                        "com.apple.CoreSimulator.SimRuntime.iOS-17-2" : [
                          {
                            "lastBootedAt" : "2024-12-27T18:43:54Z",
                            "dataPath" :
                            "\/Users\/matheus.demetrio\/Library\/Developer\/CoreSimulator\/Devices
                            \/DA5276D1-579A-45FD-92CB-3C1AD5EB425A\/data",
                            "dataPathSize" : 1104928768,
                            "logPath" :
                            "\/Users\/matheus.demetrio\/Library\/Logs\/CoreSimulator\/DA5276D1-579
                            A-45FD-92CB-3C1AD5EB425A",
                            "udid" : "DA5276D1-579A-45FD-92CB-3C1AD5EB425A",
                            "isAvailable" : true,
                            "logPathSize" : 184320,
                            "deviceTypeIdentifier" :
                            "com.apple.CoreSimulator.SimDeviceType.iPhone-15-Pro-Max",
                            "state" : "Booted",
                            "name" : "iPhone 15 Pro Max"
                          }
                        ],
                        "com.apple.CoreSimulator.SimRuntime.iOS-15-5" : [

                        ],
                        "com.apple.CoreSimulator.SimRuntime.iOS-16-4" : [

                        ],
                        "com.apple.CoreSimulator.SimRuntime.iOS-17-0" : [

                        ]
                      }
                    }
[+2341 ms] [
                      {
                        "ignored" : false,
                        "modelCode" : "MacBookPro16,1",
                        "simulator" : false,
                        "modelName" : "MacBook Pro",
                        "operatingSystemVersion" : "13.5.1 (22G90)",
                        "identifier" : "7FFCC939-1491-57D5-8F82-C08029D320DF",
                        "platform" : "com.apple.platform.macosx",
                        "architecture" : "x86_64h",
                        "interface" : "usb",
                        "available" : true,
                        "name" : "My Mac",
                        "modelUTI" : "com.apple.macbookpro-16"
                      },
                      {
                        "simulator" : true,
                        "operatingSystemVersion" : "17.2 (21C62)",
                        "available" : true,
                        "platform" : "com.apple.platform.iphonesimulator",
                        "modelCode" : "iPhone16,2",
                        "identifier" : "DA5276D1-579A-45FD-92CB-3C1AD5EB425A",
                        "architecture" : "x86_64",
                        "modelUTI" : "com.apple.iphone-15-pro-max-1",
                        "modelName" : "iPhone 15 Pro Max",
                        "name" : "iPhone 15 Pro Max",
                        "ignored" : false
                      }
                    ]
[   +1 ms] executing: xcrun devicectl --version
[ +346 ms] Exit code 0 from: xcrun devicectl --version
[        ] 355.24
[   +5 ms] executing: xcrun devicectl list devices --timeout 5 --json-output
/var/folders/s5/kzlz74dn79vfzzn64418_fkn4pbygw/T/flutter_tools.8a6pdD/core_devices.UsuLXS/core_dev
ice_list.json
[+1341 ms] No devices found.
[        ] {
             "info" : {
               "arguments" : [
                 "devicectl",
                 "list",
                 "devices",
                 "--timeout",
                 "5",
                 "--json-output",
                 "/var/folders/s5/kzlz74dn79vfzzn64418_fkn4pbygw/T/flutter_tools.8a6pdD/core_devic
                 es.UsuLXS/core_device_list.json"
               ],
               "commandType" : "devicectl.list.devices",
               "environment" : {
                 "TERM" : "xterm-256color"
               },
               "jsonVersion" : 2,
               "outcome" : "success",
               "version" : "355.24"
             },
             "result" : {
               "devices" : [

               ]
             }
           }

[  +99 ms] Waiting for a connection from Flutter on iPhone 15 Pro Max...
[   +8 ms] Checking for advertised Dart VM Services...
[  +24 ms] executing: xcrun simctl spawn DA5276D1-579A-45FD-92CB-3C1AD5EB425A log stream --style
json --predicate eventType = logEvent AND (senderImagePath ENDSWITH "/Flutter" OR senderImagePath
ENDSWITH "/libswiftCore.dylib" OR processImageUUID == senderImageUUID) AND NOT(eventMessage
CONTAINS ": could not find icon for representation -> com.apple.") AND NOT(eventMessage BEGINSWITH
"assertion failed: ") AND NOT(eventMessage CONTAINS " libxpc.dylib ")
[+1190 ms] [
                      {
                        "ignored" : false,
                        "modelCode" : "MacBookPro16,1",
                        "simulator" : false,
                        "modelName" : "MacBook Pro",
                        "operatingSystemVersion" : "13.5.1 (22G90)",
                        "identifier" : "7FFCC939-1491-57D5-8F82-C08029D320DF",
                        "platform" : "com.apple.platform.macosx",
                        "architecture" : "x86_64h",
                        "interface" : "usb",
                        "available" : true,
                        "name" : "My Mac",
                        "modelUTI" : "com.apple.macbookpro-16"
                      },
                      {
                        "simulator" : true,
                        "operatingSystemVersion" : "17.2 (21C62)",
                        "available" : true,
                        "platform" : "com.apple.platform.iphonesimulator",
                        "modelCode" : "iPhone16,2",
                        "identifier" : "DA5276D1-579A-45FD-92CB-3C1AD5EB425A",
                        "architecture" : "x86_64",
                        "modelUTI" : "com.apple.iphone-15-pro-max-1",
                        "modelName" : "iPhone 15 Pro Max",
                        "name" : "iPhone 15 Pro Max",
                        "ignored" : false
                      }
                    ]
[   +1 ms] executing: xcrun devicectl list devices --timeout 5 --json-output
/var/folders/s5/kzlz74dn79vfzzn64418_fkn4pbygw/T/flutter_tools.8a6pdD/core_devices.fv9J7f/core_dev
ice_list.json
[+1371 ms] No devices found.
[        ] {
             "info" : {
               "arguments" : [
                 "devicectl",
                 "list",
                 "devices",
                 "--timeout",
                 "5",
                 "--json-output",
                 "/var/folders/s5/kzlz74dn79vfzzn64418_fkn4pbygw/T/flutter_tools.8a6pdD/core_devic
                 es.fv9J7f/core_device_list.json"
               ],
               "commandType" : "devicectl.list.devices",
               "environment" : {
                 "TERM" : "xterm-256color"
               },
               "jsonVersion" : 2,
               "outcome" : "success",
               "version" : "355.24"
             },
             "result" : {
               "devices" : [

               ]
             }
           }

[+2483 ms] Checking for advertised Dart VM Services...
The Dart VM Service was not discovered after 30 seconds. This is taking much longer than expected...

Click "Allow" to the prompt on your device asking if you would like to find and connect devices on your local network. If you selected "Don't Allow", you can turn it on in Settings > Your App Name > Local Network. If you don't see your app in the Settings, uninstall the app and rerun to see the prompt again.
[+600003 ms] mDNS query failed. Checking for an interface with a ipv4 link local address.
[   +2 ms] Found interface "en0":
[        ] 	Bound address: "192.168.100.146" 
[        ] Found interface "utun3":
[        ] 	Bound address: "100.64.0.1" 
[  +28 ms] The mDNS query for an attached iOS device failed. It may be necessary to disable the
"Personal
           Hotspot" on the device, and to ensure that the "Disable unless needed" setting is
unchecked under
           System Preferences > Network > iPhone USB. See
https://github.com/flutter/flutter/issues/46698 for
           details.

```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.24.3, on macOS 13.5.1 22G90 darwin-x64, locale pt-BR)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.96.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!
```

</details>