Skip to content

Remote target devices

Hidenori Matsubayashi edited this page Jul 28, 2021 · 21 revisions

In embedded development, we usually install software to remote target devices. In that case, the custom-devices feature helps you develop your flutter apps.

1. Create ~/.flutter_custom_devices.json

${localPath}, ${appName}, ${hostPort}, ${devicePort} are the system reserved vars, which are automatically determined by flutter-elinux tool. Set each value appropriately according to your target device. Also, you can add multi devices to the JSON file.

~/.flutter_custom_devices.json example:

{
  "custom-devices": [
    {
      "id": "raspberry-pi4",
      "label": "Rasberry Pi 4",
      "sdkNameAndVersion": "Rasberry Pi 4",
      "enabled": true,
      "platform": "arm64",
      "backend": "wayland",
      "ping": [
        "ping", "-w", "500", "-c", "1", "192.168.0.100"
      ],
      "pingSuccessRegex": "ttl=",
      "install": [
        "scp", "-r", "${localPath}", "[email protected]:/tmp/${appName}"
      ],
      "uninstall": [
        "ssh", "[email protected]", "rm -rf \"/tmp/${appName}\""
      ],
      "runDebug": [
        "ssh", "[email protected]", "/tmp/${appName}/${appName} -b ."
      ],
      "forwardPort": [
        "ssh", "-o", "ExitOnForwardFailure=yes",
        "-L", "127.0.0.1:${hostPort}:127.0.0.1:${devicePort}", "[email protected]"
      ],
      "forwardPortSuccessRegex": "Linux"
    }
  ]
}

2. Device discovery

Make sure that the devices found by the ping command are listed.

$ flutter-elinux devices
3 connected devices:

eLinux (desktop) • elinux-wayland • flutter-tester • Ubuntu 20.04.2 LTS 5.8.0-63-generic
eLinux (desktop) • elinux-x11     • flutter-tester • Ubuntu 20.04.2 LTS 5.8.0-63-generic
eLinux (mobile)  • raspberry-pi4  • flutter-tester • Rasberry Pi 4

3. Build your flutter apps for target devices

Build for the target device. See also: Cross-building from x64 to arm64

flutter-elinux build elinux --target-arch=arm64 --target-sysroot=/opt/arm64-sysroot \
    --system-include-directories=/usr/aarch64-linux-gnu/include/c++/9/aarch64-linux-gnu \
    --debug

4. Run your flutter apps on your target device

Note that run sub-command for custom-devices is supported debug mode only.

$ flutter-elinux run -d raspberry-pi4

5. Other commands

Install your flutter app bundle

$ flutter-elinux install -d raspberry-pi4

Uninstall your flutter app bundle

$ flutter-elinux uninstall -d raspberry-pi4
Clone this wiki locally