'I'm trying to run my flutter app on an emulator from VS code and I get an error saying it cannot find the path to my main.dart file
I want to run my flutter program on an emulator from VS Code. The idea is that when I run a debug session in VS Code, the app should appear on the emulator. I have the emulator open and connected to VS Code, however, when I try to debug I get an error that says "Error: Error when reading 'bin/main.dart': The system cannot find the path specified. ".
**This is my launch.json file in VS Code**
"version": "0.2.0",
"configurations": [
{
"name": "Dart",
"program": "bin/main.dart",
"request": "launch",
"type": "dart"
}
]
}
The path to my flutter app is ...wordpair_generator\lib\main.dart so I tried changing the JSON file code to the following
"program": "lib/main.dart",
I received an error saying "Error: Error when reading 'lib/main.dart': The system cannot find the path specified. " so I then tried changing the JSON file to the following
"program": "wordpair_generator/lib/main.dart"
Now I don't get an error, the debug runs, but nothing happens. My app does not appear on my emulator.
UPDATE I left the program running while I left to make tea, and the program worked on the emulator. If anyone is having a similar issue, I would recommend letting the program run for about 5 minutes. Now whenever I run the program it only takes about 30 seconds.
Solution 1:[1]
I suppose you are not solving that issue by making tea imao.
Try to change it into
"program": "${workspaceFolder}/lib/main.dart",
You may open the wordpair_generator
folder in vscode, so that ${workspaceFolder}
resolves to that.
For more info you are welcome to look at official documentation:
${workspaceFolder} - the path of the folder opened in VS Code
For others trying to figure out the correct launch.json
, actually you could just press F5 on the main.dart (ensure you have flutter extension installed and no existing launch.json
), then you may find the plugin automatically set for you. That's the lazy way.
Solution 2:[2]
Just delete .vscode/launch.json
file and run, it worked for me
Solution 3:[3]
This works for me. Remember to change your program path to your file path.
{
// 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"
}
]
}
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 | LoL |
Solution 2 | saigopi.me |
Solution 3 | Ellix4u |