dart2native
Note: To execute Dart code without AOT compiling it, use dart
, the standalone Dart VM.
The output of dart2native
is eithera standalone executable (the default)or an AOT snapshot that you can run with the .A standalone executable is native machine code that’s compiled fromthe specified Dart file and its dependencies,plus a small Dart runtime that handlestype checking and garbage collection.
An AOT snapshot doesn’t include the Dart runtime.Consider using snapshots if you’re distributing multiple programsand disk space is limited.
You can distribute and run that executable like you wouldany other executable file:
To create an AOT snapshot, add -k aot
to the command:
You can then run the app using the dartaotruntime
command:
- No cross-compilation support ()
- The compiler supports creating machine code only forthe operating system it’s running on.You need to run the compiler three times —on macOS, Windows, and Linux —to create executables for all three operating systems.A workaround is to use a CI (continuous integration) providerthat supports all three operating systems.
- The format of the executables isn’t compatible withstandard signing tools such as codesign and SignTool.
- No support for dart:mirrors and dart:developer
- The code compiled by
dart2native
can use all of the other librariesthat the Dart VM supports.For a complete list of the core libraries you can use,see the All and AOT entries in thetable of core Dart libraries.
Tip: If one of these issues is important to you, let the Dart team know by adding a “thumbs up” to the issue.
The first argument to dart2native
is the path to the main Dart file:
You can use the following options:
- or
—define=<key>=<value>
- Defines an environment variable.To specify multiple variables, use multiple options oruse commas to separate key-value pairs.
—enable-asserts
- Enables .
- Displays help for all options.
-k (aot|exe)
or—output-kind=(aot|exe)
- Specifies the output type, where
exe
is the default(a standalone executable). To generate an AOT snapshot,use-k aot
. -o <path>
or—output=<path>
- Generates the output into . If you don’t use this option,the output goes into a file next to the main Dart file.Standalone executables have the suffix
.exe
, by default;the AOT snapshot suffix is.aot
. -p <path>
or—packages=<path>
- Specifies the path to the package resolution configuration file.For more information, seePackage Resolution Configuration File.
- Displays more information.