How to change VS CODE's default emulator?

Viewed 2557

I have installed flutter and Android iOS Emulator plugins on VS CODE, and this is the result of flutter emulators command inside the VS CODE's built-in terminal:

3 available emulators:
Nexus_5x       • Nexus_5x       • Google • android
Pixel_2_API_29 • Pixel 2 API 29 • Google • android
pixel_xl       • pixel_xl       • Google • android

To run an emulator, run 'flutter emulators --launch <emulator id>'.
To create a new emulator, run 'flutter emulators --create [--name xyz]'.

You can find more information on managing emulators at the links below:
  https://developer.android.com/studio/run/managing-avds
  https://developer.android.com/studio/command-line/avdmanager

But the default emulator it selects in the right-bottom corner of the IDE is Chrome(web javascript). I wan to change the default choice to one of the Android emulators if is it possible?

3 Answers

There isn't really a "default" here, VS Code asks Flutter to monitor devices being connected/disconnected and usually selects the "last device connected" as they appear. If you have multiple devices available, the one selected will depend on the order they are discovered at startup.

If you're not using Flutter web for this project, I think there are two things that could help:

  • run flutter config --no-enable-web to prevent Chrome being an available device at all (this is global)
  • removing the web folder from your project (this would prevent Chrome being a valid device for this specific project)
  1. Create .vscode/launch.json file at the root of your project
  2. launch.json content:
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Flutter",
      "request": "launch",
      "type": "dart",
      "args": ["-d", "<MY_DEVICE_ID>"]
    }
  ]
}

Replace <MY_DEVICE_ID> with the id of the desired device, which could be found by using flutter devices command (it lists available devices).

I faced the same problem and solved it the following way.

  1. delete all your android emulators.

  2. re-install a new android emulator.

  3. run the emulator using this:

    flutter emulators --launch 'EmulatorName'

  4. from terminal or cmd change your directory to your project folder

  5. use this command:

    flutter run

it will automatically run on the android device you started earlier. and it will keep running on that emulator for the rest of the time.

keep in mind if you get an error saying

can't find pubspec.yaml

it means you are still not in your project folder, so change the directory one step to your project folder.

Related