Run Flutter Applications on Ubuntu Core

Key Value
Summary Learn how to build and deploy a Flutter application on Ubuntu Core by leveraging Ubuntu Frame
Categories iot
Difficulty 3
Author Bugra Aydogar bugra.aydogar@canonical.com

Overview

Duration: 3:00

This document has been supersede:

6 Likes

after following the above steps, I got this.

asimfarooq5@ubuntu:~$ flutterdemo 
error: error running snapctl: snap "flutterdemo" has no plug or slot named "pulseaudio"
WARNING: pulseaudio interface not connected! Please run: /snap/flutterdemo/current/bin/setup.sh
Setting up watches.
Watches established.
asimfarooq5@ubuntu:~$ snap logs flutterdemo
2022-01-11T14:39:18Z flutterdemo.daemon[1620]: WARNING: pulseaudio interface not connected! Please run: /snap/flutterdemo/current/bin/setup.sh
2022-01-11T14:39:18Z -[1620]: g_dbus_proxy_new_sync: assertion 'G_IS_DBUS_CONNECTION (connection)' failed
2022-01-11T14:39:18Z flutterdemo.daemon[1620]: Couldn't open libGLESv1_CM.so.1: libGLESv1_CM.so.1: cannot open shared object file: No such file or directory
2022-01-11T14:39:18Z systemd[1]: snap.flutterdemo.daemon.service: Main process exited, code=exited, status=1/FAILURE
2022-01-11T14:39:18Z systemd[1]: snap.flutterdemo.daemon.service: Failed with result 'exit-code'.
2022-01-11T14:39:18Z systemd[1]: snap.flutterdemo.daemon.service: Scheduled restart job, restart counter is at 6.
2022-01-11T14:39:18Z systemd[1]: Stopped Service for snap application flutterdemo.daemon.
2022-01-11T14:39:18Z systemd[1]: snap.flutterdemo.daemon.service: Start request repeated too quickly.
2022-01-11T14:39:18Z systemd[1]: snap.flutterdemo.daemon.service: Failed with result 'exit-code'.
2022-01-11T14:39:18Z systemd[1]: Failed to start Service for snap application flutterdemo.daemon.

That isn’t in the instructions and won’t work: There’s no Wayland server in your user session.

This is your problem: there’s an error in your snap packaging that prevents libGLESv1_CM.so.1 being found. Please recheck your snap recipe.

this is my “snapcraft.yaml”

name: flutterdemo 
base: core18 
version: '0.1' 
summary: flutterdemo 
description: flutterdemo


grade: devel
confinement: devmode 

slots:
 dbus-flutterdemo:
   interface: dbus
   bus: session
   name: com.example.flutterdemo

apps:
  daemon:
    daemon: simple
    restart-condition: always
    command-chain:
      - bin/run-daemon
      - bin/wayland-launch
    command: bin/flutterdemo
    extensions: [flutter-master]
    environment:
      GDK_GL: gles

  flutterdemo:
    command-chain:
      - bin/wayland-launch
    command: flutterdemo
    extensions: [flutter-master]
    environment:
      GDK_GL: gles

parts:
  flutterdemo:
   source: .
   plugin: flutter
   flutter-target: lib/main.dart
  
  mir-kiosk-snap-launch:
    plugin: dump
    source: https://github.com/MirServer/mir-kiosk-snap-launch.git
    override-build:  $SNAPCRAFT_PART_BUILD/build-with-plugs.sh opengl wayland
    stage-packages:
      - inotify-tools

layout:
  /usr/share/fonts:
    bind: $SNAP/usr/share/fonts
  /etc/fonts:
    bind: $SNAP/etc/fonts
  /usr/share/icons:
    bind: $SNAP/usr/share/icons

I’m testing on nvidia, does this matters ?

At what point in the tutorial are you? “Running Your Flutter Application Snap on Ubuntu Core”?

What device (or VM) are you running on?

yeah, I’m trying on UbuntuCore in Qemu(VM).

after removing pulseaudio from snapcraft.yaml

asimfarooq5@ubuntu:~$ flutterdemo 
Setting up watches.
Watches established.
asimfarooq5@ubuntu:~$ snap logs flutterdemo
2022-01-12T11:25:28Z flutterdemo.daemon[2498]: + exec /snap/flutterdemo/x2/bin/wayland-launch /snap/flutterdemo/x2/bin/flutterdemo
2022-01-12T11:25:28Z -[2498]: g_dbus_proxy_new_sync: assertion 'G_IS_DBUS_CONNECTION (connection)' failed
2022-01-12T11:25:28Z flutterdemo.daemon[2498]: Couldn't open libGLESv1_CM.so.1: libGLESv1_CM.so.1: cannot open shared object file: No such file or directory
2022-01-12T11:25:28Z systemd[1]: snap.flutterdemo.daemon.service: Main process exited, code=exited, status=1/FAILURE
2022-01-12T11:25:28Z systemd[1]: snap.flutterdemo.daemon.service: Failed with result 'exit-code'.
2022-01-12T11:25:28Z systemd[1]: snap.flutterdemo.daemon.service: Scheduled restart job, restart counter is at 5.
2022-01-12T11:25:28Z systemd[1]: Stopped Service for snap application flutterdemo.daemon.
2022-01-12T11:25:28Z systemd[1]: snap.flutterdemo.daemon.service: Start request repeated too quickly.
2022-01-12T11:25:28Z systemd[1]: snap.flutterdemo.daemon.service: Failed with result 'exit-code'.
2022-01-12T11:25:28Z systemd[1]: Failed to start Service for snap application flutterdemo.daemon.

This probably won’t work, but I’d like to verify that it doesn’t to eliminate possible causes, could you try running this:

$ echo "env -u GDK_GL \$SNAP/bin/flutterdemo" | sudo snap run --shell flutterdemo
1 Like

yeah, It worked :grin:

Cool. In that case, you simply need to remove the GDK_GL: gles lines from your snapcraft recipe and repackage. These lines are there because they are needed on some devices (e.g. RPi4). Unfortunately, it seems that they break things on QEMU.

We’ll need to do some more investigation into how to get this example working across all devices.

1 Like

yeah, It working fine, I’ll repackage this for arm64 and test on RPi3&4.

OK, the root cause is that the gnome-3-28-1804 snap is intended for desktop use and, since for amd64, there’s no need for GLES it doesn’t contain libgles1.

There’s another approach to building Flutter snaps for Core that does work across devices. The general approach is described here:

https://github.com/MirServer/iot-example-graphical-snap/wiki/Embedding-IOT-GUI-with-Ubuntu-Frame

With a Flutter specific branch here:

https://github.com/MirServer/iot-example-graphical-snap/tree/Flutter-demo

I have build the snap with same config removing the GDK_GL: gles lines and got this in snap logs:

Failed to start Flutter renderer: Unable to create a GL context

I’d expect to see that on RPi4.

In any case, I’ve just updated the snapcraft.yaml in the tutorial. That should work everywhere.

I tested with RPi3, let me test the updated config.

i’d do that type of detection at runtime instead of build time:

  gles-on-arm:
    plugin: nil
    override-build: |
      snapcraftctl build
      mkdir -p $SNAPCRAFT_PART_INSTALL/bin/
      echo 'case $(arch) in aarch64|armv7l) export GDK_GL=gles;; esac' > $SNAPCRAFT_PART_INSTALL/bin/gl-launch
      echo 'exec "$@"' >> $SNAPCRAFT_PART_INSTALL/bin/gl-launch
      chmod a+x $SNAPCRAFT_PART_INSTALL/bin/gl-launch

:+1: new snapcraft.yaml in the tutorial works fine for both amd64/arm64. :grin:

1 Like

There are many equivalent ways to do this. :man_shrugging:

Hi, I’m trying to run this example in a raspberry pi 4 using ubuntu core 20, but after install ubuntu-frame and the super-cool-app snap, I only get the grey wallpaper from ubuntu-frame but no signal of the flutter app.

I added this to the snapcraft.yaml file to make the snap compatible with armhf architercture:

architectures:
    - build-on: amd64
      run-on: armhf

Also, when I run super-cool-app on the command line, I get this messages:

error: error running snapctl: snap "super-cool-app" has no plug or slot named "pulseaudio"

WARNING: pulseaudio interface not connected! Please run: /snap/super-cool-app/current/bin/setup.sh

/snap/super-cool-app/x2/bin/wayland-launch: 22: /snap/super-cool-app/x2/bin/wayland-launch: inotifywait: Exec format error

Any help will be very appreciated.