Reputation:
Is it possible to run this code in Android studio without firing up any device, I just want to print it to the console.
void main() {
print("Hello World");
}
Note:
I am not looking for DartPad
or any other online IDE to run Dart code.
Upvotes: 1
Views: 2412
Reputation: 2835
As of 2024, you might need to create a run configuration as a Dart console in the latest Android Studio. Follow the below steps to get it working.
main.dart
dropdown button in the toolbar beside the green play button and choose the Edit Configurations...
option.+
button to open the Add New Configuration
menuDart Command Line App
. Enter Name
for run config, Choose the path to your Dart file:
Apply
and the OK
buttons to close the window.Upvotes: 1
Reputation: 167
in your Dart file right click on the green arrows in front of your main()
function:
then click on the dart icon from the popup menuCreate ...
and then OK
:
now you can run it without the simulator:
And get the console output in the Run window:
Upvotes: 3
Reputation: 90015
On a Unix-like system (e.g. Linux, macOS), if dart
is in your executable PATH
, you can add a shebang line to your .dart
file:
#!/usr/bin/env dart
void main() {
print("Hello World");
}
and mark your file executable (chmod a+x your_file.dart
). Then you can run your_file.dart
directly without needing to run dart your_file.dart
explicitly.
(If the dart
binary is not in PATH
, then you would need to use #!/full/path/to/dart
as the first line instead.)
On Windows, you could set up a file association for .dart
files.
Upvotes: 1