-
Notifications
You must be signed in to change notification settings - Fork 0
The flutter daemon mode
The flutter command-line tool supports a daemon server mode for use by IDEs and other tools.
flutter daemon
It runs a persistent, JSON-RPC based server to communicate with devices. IDEs and and other tools can start the flutter tool in this mode and get device addition and removal notifications, as well as being able to programmatically start and stop apps on those devices.
The daemon speaks JSON-RPC to clients. It uses stdin and stdout as the protocol transport. To send a command to the server, create your command as a JSON-RPC message, encode it to json, surround the encoded text with square brackets, and write it as one line of text to the stdin of the process:
[{"method":"daemon.version","id":0}]
The response will come back as a single line from stdout:
[{"id":0,"result":"0.1.0"}]
All requests and responses should be wrapped in square brackets. This ensures that the communications are resilient to stray output in the stdout/stdin stream.
id is an opaque type to the server, but ids should be unique for the life of the server. A response to a particular command will contain the id that was passed in for that command.
Each command should have a method field. This is in the form 'domain.command'.
Any params for that command should be passed in through a params field. Here's a example request/response for the device.getDevices method:
[{"method":"device.getDevices","id":2}]
[{"id":2,"result":[{"id":"702ABC1F-5EA5-4F83-84AB-6380CA91D39A","name":"iPhone 6","platform":"ios_x64","available":true}]}]
The version() command responds with a String with the protocol version.
The shutdown() command will terminate the flutter daemon. It is not necessary to call this before shutting down the daemon; it is perfectly acceptable to just kill the daemon process.
The daemon.logMessage event is sent whenever a log message is created - either a status level message or an error. The JSON message will contains an event field with the value daemon.logMessage, and an params field containing a map with level, message, and (optionally) stackTrace fields.
The start() command is used to start applications.
-
deviceId: The device to launch the app on; this is required. -
projectDirectory: The project directory; this is required. It is used to determine the application to start. -
startPaused: Start the VM in a paused mode. -
route: A string; the route to use when restoring the application. -
mode: One of eitherdebug,profile, orrelease. -
target: Optional; the target file to start. -
hot: Optional; whether to start the application using--hotmode
On success, returns a map with the fields:
-
appId: this is is used when sending app events, and can be used by clients to stop the app (app.stop). deviceIddirectorysupportsRestart
The restart() restarts the given application. It returns a bool to indicate success or failure in restarting the app.
-
appId: the id of a previously started app; this is required. -
fullRestart: optional; whether to do a full (rather than an incremental) restart of the application
The stop() command takes one parameter, appId. It returns a bool to indicate success or failure in stopping an app.
-
appId: the id of a previously started app; this is required.
The discover() command takes one parameter, a deviceId. It returns a list of applications discovered on the device. Each application is represented by a map with two fields, an id - an Android or iOS application id - and an observatoryDevicePort. The observatoryDevicePort is the device port to connect to to debug the application. The port may first have to be made accessable via device.forward.
This is sent when an app is started. The params field will be a map with the fields appId, directory, and deviceId.
This is sent when an observatory port is available for a started app. The params field will be a map with the fields appId and port. An optional field, baseUri, is populated if a path prefix is required for setting breakpoints on the target device.
This is sent when output is logged for a running application. The params field will be a map with the fields appId and log. The log field is a string with the output text. If the output indicates an error, an error boolean field will be present, and set to true.
If this is a progress event, it will contain the fields progress (a bool with the value true) and id, an opaque identifier. The ending progress event for a progress pair will have a finished bool field with the value true and will not contain a log (message) field.
This is sent when an app is stopped. The params field will be a map with the field appId.
Return a list of all connected devices. The params field will be a List; each item is a map with the fields id, name, and platform.
Turn on device polling. This will poll for newly connected devices, and fire device.added and device.removed events.
Turn off device polling.
Forward a host port to a device port. This call takes two required arguments, deviceId and devicePort, and one optional argument, hostPort. If hostPort is not specified, the host port will be any available port.
This method returns a map with a hostPort field set.
Removed a forwarded port. It takes deviceId, devicePort, and hostPort as required arguments.
This is sent when a device is connected (and polling has been enabled via enable()). The params field will be a map with the fields id, name, and platform.
This is sent when a device is disconnected (and polling has been enabled via enable()). The params field will be a map with the fields id, name, and platform.
See the source for the daemon protocol and implementation.
