Trouble getting Flutter to run in debug mode in VS Code - flutter

I am able to run my Flutter project in an emulator in Android Studio. I'm trying to run that same code in debug mode (f5) in VS Code, but I get an error saying:
Set the 'program' value in your launch config (eg 'lib/main.dart') then launch again.
So I updated my launch config to the following:
{
"version": "0.2.0",
"configurations": [
{
"name": "Dart & Flutter",
"request": "launch",
"type": "dart",
"program": "lib/main.dart"
}
]
}
After that update, when I try f5 I get the following error:
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.
I DO have a main.dart file??
Any help would be greatly appreciated.

instead of "program": "lib/main.dart" try "flutterMode": "debug"
{
"version": "0.2.0",
"configurations": [
{
"name": "Dart & Flutter",
"request": "launch",
"type": "dart",
"flutterMode": "debug"
}
]
}

For some reason, VS Code was using the launch config from a different project folder that was in my workspace. After removing that project, f5 worked as expected.

flutter run would help, In my case first run flutter doctor , later do resolve missing configs as mentioned and then Flutter run

Related

Flutter run works from command line but not with VsCode

I installed Flutter and I have a project that used it (Flutter Web).
As IDE I use VsCode.
When I run the app using command line (flutter run --no-sound-null-safety) it works well, instead when I use VsCode I get this error:
ChromeProxyService: Failed to evaluate expression 'Future': InternalError: No frame with index 17.
ChromeProxyService: Failed to evaluate expression 'that': InternalError: No frame with index 17.
...
I launch the app with fn+f5 and I created this .vscode/launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "Web nosound null",
"type": "dart",
"request": "launch",
"deviceId": "chrome",
"args": [
"--no-sound-null-safety"
]
},
{
"name": "Web sound null",
"type": "dart",
"request": "launch",
"deviceId": "chrome",
"args": []
},
]
}
I tried also flutter clean but nothing changes, also uninstall and reinstall Flutter seems not to solve the problem.
VsCode is updated.
What am I wrong?

Configured debug type 'hl' not supported

I have installed hash link on my linux machine (works on the terminal as expected) and upon pressing F5 from vscode for my heaps.io program, it says Configured debug type 'hl' not supported. So I tried searching for hashlink on the extensions market and found no results. I have copied my launch.json from the heaps.io tutorial website. What should I do?
Launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "HashLink",
"request": "launch",
"type": "hl",
"cwd": "${workspaceFolder}",
"preLaunchTask": {
"type": "haxe",
"args": "active configuration"
}
}
]
}
Where the launch.json file can be found
https://heaps.io/documentation/hello-hashlink.html
Ok I made it work! For some reason I had to copy all the required libraries from /usr/local/lib to /lib64 for vscode to launch my application through hashlink.
Also about the hashlink, I just installed the .vsix version of hashlink of version 1.1.12. The versions above that don't seem to work with the latest vscode version.

Flutter VsCode error: You don't have an extension for debugging YAML

I get this error each time I try to start my app in VsCode
You don't have an extension for debugging YAML. Should we find a YAML
extension in the Marketplace?
It was working before I add a font in pubspec.yaml, restarted my app and it didn't work anymore. I tried to restart VsCode, undo my changes, launch "flutter pub get" many times but nothing seems to work.
Click on "open a file", then navigate to the main.dart file and then click debug and run.
This mostly happens when you current file is the pubspec.yaml file. Just close or switch the main.dart or any .dart file. And it will work. Worked for me.
Just select main.dart file to start your app
Click debug and run.
The reason is that you are clicking on "Run and Debug" when you are at pubspec.yaml file. Just close it and go to main.dart and then Click on "Run and Debug".
Add .vscode/launch.json in your root folder
{
"version": "0.2.0",
"configurations": [
{
"name": "flutter_project", //<- Your Project Name
"request": "launch",
"type": "dart",
"program": "lib/main.dart"
},
{
"name": "Flutter",
"type": "dart",
"request": "launch",
"program": "lib/main.dart"
},
]
}
'For that go to RUN > ADD Configuration > Dart & Flutter'
This worked for me! Thanks Joris
It seems that Dart & Flutter run configuration has to be selected.
For that go to RUN > ADD Configuration > Dart & Flutter

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.
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.
2. Check that lib/main.dart exists. If your main function is different, edit the launch.json file and change the program.
delete your launch.json file and then open your debug menu and click on create a launch.json file
From the dropdown, select dart and Flutter and run the app again
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
flutter clean
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());
}
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"
}
]
}
Adding the correct root folder as cwd to the launch config fixed it for me.
"configurations": [
{
"name": "Flutter",
"type": "dart",
"request": "launch",
"program": "lib/main.dart",
"cwd": "${workspaceFolder}"
}
]
Pretty sure this was not the answer when the question was asked, but I got the same error message apparently after a recent update of the flutter extension in VS Code.
It looks like they changed how the working directory is deduced if not specified: https://dartcode.org/releases/v3-50/
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"
}
]

Debug mode does not activate breakpoint

I am trying to use debug mode in my react native application with visual studio code. I am using the command npx react-native run-android. It is activating the react native debugger, but it is not reaching any breakpoint in my application.
I did not find any tutorials to activate debug with npx, so could you guys show me one or explain me what is happening wrongly in this setup?
this is my launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug React Native",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "launch",
"platform": "android",
"sourceMaps": true,
"outDir": "${workspaceRoot}/.vscode/.react"
},
]
}
An interesting thing it is happening is once it is running the application if I click on the start debugging button my application restarts and it shows a message on debug console:
Launched debug configuration contains 'program' property which is deprecated and will be removed soon. Please replace it with: "cwd": "${workspaceFolder}"
Could not debug. The "path" argument must be of type string. Received type undefined
Since I have not received any answer, I took 3 days to discovered what was happening.
this is the correct configuration:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to packager",
//"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "attach",
"sourceMaps": true,
"cwd": "${workspaceFolder}",
//"outDir": "${workspaceRoot}/.vscode/.react"
},
]
}
Must run the command npx react-native run-android
Once the android emulator is running batch job must be stopped in the terminal
Go to the debug tab in vs code and run the application
ctrl + m on android emulator
click on debug option
Those were the baby steps that I did in order to have the application run in debug mode.