spawnAttachDaemon function

Future<DaemonTransport> spawnAttachDaemon({
  1. required String flutterBinary,
  2. required String deviceId,
  3. String? adbPath,
})

Spawns <flutterBinary> attach --machine -d <deviceId> and returns the transport. flutterBinary must be the session manifest's recorded-SDK binary (never PATH) — the caller enforces that via checkDevSession.

adbPath (the oka-resolved platform-tools binary) is prepended to the child's PATH: the flutter tool discovers devices through adb, and the oka-managed SDK dir is often not on the ambient PATH (live e2e finding, 2026-09-07 — without this, attach reports "No supported devices found").

Implementation

Future<DaemonTransport> spawnAttachDaemon({
  required String flutterBinary,
  required String deviceId,
  String? adbPath,
}) async {
  final environment = <String, String>{...Platform.environment};
  if (adbPath != null && adbPath.isNotEmpty) {
    final dir = p.dirname(adbPath);
    environment['PATH'] = '$dir:${environment['PATH'] ?? ''}';
  }
  final process = await Process.start(
    flutterBinary,
    flutterAttachMachineArgs(deviceId: deviceId),
    environment: environment,
  );
  return ProcessDaemonTransport(process);
}