Skip to content

Provide a command to get the ID of the selected device for use in tasks #4677

@ajamespro

Description

@ajamespro

I'm trying to pass the mobile deviceId to a flutter preLaunchTask. Minimal sample below, but ultimately it's a simctl script that uses booted as the device id. However, this breaks down when I have multiple simulator devices booted, so I'm trying to explicitly run the preLaunch script with the target device.

Does someone know how to do this? I've tried almost everything I could think of with variable substitution and environment variables (printenv shows nothing useful), but I can't find any hook into deviceId. It should be the same parameter passed to the -d argument. Caveat: I can't use an explicit deviceId in the launch config because the config is checked in and shared with others, and we all use various versions of devices and Xcode.

Can you help? :/

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Test My Shtuff",
      "type": "dart",
      "request": "launch",
      "flutterMode": "debug",
      "program": "./integration_test/",
      "templateFor": "./integration_test/",
      "preLaunchTask": "Thing that needs deviceId",
    },
  ]
}

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Thing that needs deviceId",
      "type": "shell",
      "command": "echo $DEVICE_ID", // <-- what do?
    },
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    in flutterRelates to running Flutter appsin tasksRelates to VS Code tasks, such as those provided by Task Providersis enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions