Can't launch my flutter app with VScode and Android Studio Emulator

Viewed 5757

I can't launch my flutter app, this is the message I get when I try to run with debbug and without debbug mode:

Your launch config references a program that does not exist. If you have problems launching, check the "program" field in your ".vscode/launch.json" file.

My .json file by default:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Dart",
      "program": "lib/main.dart",
      "request": "launch",
      "type": "dart"
    }
  ]
 

I run flutter doctor:

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[√] Android Studio (version 3.6)
[√] VS Code (version 1.46.1)
[√] Connected device (1 available)

! Doctor found issues in 1 category.

And accepted all the licenses.

Thank you.

6 Answers

Consider these two:


1. Make sure that you opened the root of the project, not a folder higher. So that .vscode folder will be created on the same level as lib folder.

Screen of vscode


2. Check that lib/main.dart exists. If your main function is different, edit the launch.json file and change the program.

Screen of vscode


delete your launch.json file and then open your debug menu and click on create a launch.json file

enter image description here

From the dropdown, select dart and Flutter and run the app again

enter image description here

if you are facing this problem kindly check the following steps Try to give a perfect path to your main.dart file in flutter app from launch.json file eg.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Dart",
      "program": "shop_app/lib/main.dart",
      "request": "launch",
      "type": "dart"
    }
  ]
}

if it does not work then from the terminal type

  1. flutter clean
  2. flutter run

Make sure the configurations program path is the same path of your main.dart or wherever your main method is.

void main() {
  runApp(MyApp());
}

Make sure the configurations program path is the same

This works for me.

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Dart & Flutter",
        "request": "launch",
        "type": "dart",
        "program": "lib/main.dart"
    }
]

}

Better add the complete path and it worked for me. This has occurred since I have moved my main. dart file from lib to new folder widgets. once I gave the complete path it worked.

"configurations": [

    {
        "name": "exp_app",
        "request": "launch",
        "type": "dart",
        "program": "E:\\FLUTTER\\exp_app\\lib\\widgets\\main.dart"
    }
]
Related