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

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.



Solution 1:[1]

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

Solution 2:[2]

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


Solution 3:[3]

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

Solution 4:[4]

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

Solution 5:[5]

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"
    }
]

}

Solution 6:[6]

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"
    }
]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ByteMe
Solution 2 Mahdi-Malv
Solution 3 Anmol Shah
Solution 4 FJCG
Solution 5 Ellix4u
Solution 6 desertnaut