Flutter for Embedded Linux (eLinux)

repository·main·Indexed 20 days ago

https://github.com/sony/flutter-elinux

A non-official extension to the Flutter SDK for building, debugging, and running Flutter applications on embedded Linux devices. It provides a lightweight alternative to standard Linux desktop builds, supporting arm64 and x64 architectures with display backends including Wayland, X11, and Direct Rendering Module (DRM). The toolset includes a specialized CLI wrapper for managing the eLinux engine, cross-compilation, and remote debugging.

Tokens
9.7K
Snippets
34
Records
49
Agent score
70%

What's inside flutter-elinux

  1. Overview of flutter-elinux features and backends

    main

    Core Features

    • Optimized for Embedded Systems: Lightweight compared to Flutter Linux desktop (avoids X11 and GTK dependencies).
    • Architecture Support: arm64 and x64.
    • Development Workflow: Supports cross-building (x64 to arm64) and remote debugging/installation on target devices.
    • API Compatibility: Maintains compatibility with Flutter desktop for Windows and GLFW, including MethodChannel and EventChannel.

    Supported Display Backends

    • Wayland
    • Direct Rendering Module (DRM):
      • Generic Buffer Management (GBM)
      • EGLStream (for NVIDIA devices)
    • X11

    Input Support

    • Keyboard, mouse, and touch inputs.
  2. Set up the native_texture_view example project

    main

    To use the native_texture_view example project, you must link it to your local installation of the flutter-elinux SDK by updating the path dependency in the project's pubspec.yaml file. Replace the placeholder path with the absolute path to your flutter-elinux/packages/flutter_elinux directory.

    flutter_elinux: 
      # Replace this with the absolute path to your flutter-elinux directory
      path: /home/hidenori/work/flutter/flutter-elinux/packages/flutter_elinux
  3. Install flutter-elinux

    main

    To install the flutter-elinux SDK, clone the repository, move it to a system directory (e.g., /opt/), and add the bin directory to your PATH.

    $ git clone https://github.com/sony/flutter-elinux.git
    $ sudo mv flutter-elinux /opt/
    $ export PATH=$PATH:/opt/flutter-elinux/bin
  4. Run a Flutter sample app on a Wayland compositor

    main

    To run Flutter apps on Wayland, you must first install and launch a Wayland compositor (such as Sway or Weston). Note that Weston version 9 has known issues; Sway is recommended.

    1. Install and launch Sway:
    $ sudo apt install sway
    $ sway &
    1. Verify connected devices:
    $ flutter-elinux devices
    1. Create and run the app:
    $ flutter-elinux create sample
    $ cd sample
    $ flutter-elinux run -d elinux-wayland
  5. Build constraints and limitations for eLinux

    main

    When using flutter elinux, be aware of the following technical constraints:

    1. x86 ABI Limitation: The x86 architecture does not support AOT (Ahead-of-Time) compilation. If you attempt a precompiled build for x86, the build will fail.
    2. Host/Target Architecture Restriction: Cross-building for x64 on an arm64 host is not supported.
    3. Self-Building on arm64: When building on an arm64 host, the tool uses the linux-desktop gen_snapshot artifact for arm64 because eLinux-specific artifacts for arm64 do not yet support self-building.
  6. How eLinux device discovery works

    main

    The flutter-elinux toolset uses a specialized device discovery mechanism to identify available targets for running Flutter applications. It discovers two types of devices:

    1. Local Desktop Backends: The discovery process automatically includes the current host machine as a target using either the wayland or x11 backend (e.g., elinux-wayland or elinux-x11).
    2. Remote eLinux Devices: The tool scans for remote devices based on configurations defined in ELinuxRemoteDevicesConfig. A remote device is considered available if its configured pingCommand executes successfully and the output matches the pingSuccessRegex.

    This discovery is integrated into the standard Flutter device management workflow via ELinuxDeviceManager and ELinuxDeviceDiscovery.

  7. Understand Hybrid Composition Platform Views in eLinux

    main

    Hybrid composition is an alternative to texture-based platform views where the native view is composited directly with the Flutter view.

    Key characteristics of _HybridELinuxViewControllerInternals:

    • requiresViewComposition: Returns true, indicating that the view relies on Flutter's view composition mechanism.
    • Limitations: Unlike texture-based views, the current implementation for hybrid composition in eLinux does not support manual textureId retrieval, setSize, or setOffset via the internal controller.
    • Disposal: When disposing a hybrid view, the dispose method is invoked on the SystemChannels.platform_views channel with the hybrid flag set to true.
  8. Configure remote eLinux devices

    main

    Remote eLinux devices are discovered by iterating through configurations provided by ELinuxRemoteDevicesConfig. For a remote device to be successfully detected and added to the list of available Flutter devices, its configuration must satisfy the following criteria:

    • Enabled: The enabled flag must be set to true.
    • Connectivity: The pingCommand must return an exit code of 0 within a 10-second timeout.
    • Validation: The standard output (stdout) of the pingCommand must contain a string matching the pingSuccessRegex.

    When these conditions are met, the device is registered with the following properties derived from its configuration:

    • id: The unique identifier for the device.
    • targetArch: The device's platform architecture.
    • backendType: The communication/display backend (e.g., wayland, x11).
    • sdkNameAndVersion: The specific SDK version associated with the device.
  9. Understand eLinux build targets and application modes

    main

    The flutter-elinux build system uses specific target classes to manage different build modes and asset bundling for embedded Linux.

    • Debug Mode (DebugELinuxApplication): Uses a kernel blob (kernel_blob.bin), VM snapshot data, and isolate snapshot data for development. It also includes ELinuxPlugins as a dependency.
    • Release Mode (ReleaseELinuxApplication): Uses Ahead-of-Time (AOT) compilation. It depends on ELinuxAotElf to generate the app.so shared library and ELinuxPlugins for native functionality.
    • Asset Bundling (ELinuxAssetBundle): Responsible for preparing the flutter_assets directory, which includes the necessary runtime files and assets required by the engine.
  10. How eLinux workflow applies to host platforms

    main

    The ELinuxWorkflow is active when the host machine is running a Linux operating system. Specifically, it applies to:

    • linux_x64 (64-bit Intel/AMD)
    • linux_arm64 (64-bit ARM)

    When this workflow is active, the toolchain supports launching and listing devices for embedded Linux development.

  11. Understand Texture-based Platform Views in eLinux

    main

    In flutter-elinux, texture-based platform views allow embedding native content into the Flutter widget tree by rendering the native content to a texture that Flutter can display.

    Key characteristics of TextureELinuxViewController:

    • textureId: Provides the unique identifier for the texture used by Flutter to render the native view.
    • requiresViewComposition: For texture-based views, this returns false, meaning the view does not require Flutter's view composition layer to manage its rendering.
    • Lifecycle: The view is managed through _sendCreateMessage (initialization with size and position), _sendResizeMessage (updating dimensions), and _sendDisposeMessage (cleanup).