简体   繁体   中英

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.

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.

只需删除.vscode/launch.json文件并运行,它对我.vscode/launch.json

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM