Debugging flutter snap

Hey there,

I am trying to get a flutter application to work as a snap package, but the application crashes at a certain point. The application is functional when built for linux.

I am using core22 with the gnome extension and the flutter plugin.

When running the application as a linux application, I get debug logs from flutter. However, in my snap I don’t see these logs. I am assuming this is because the application is built as release, but I am not sure.

I have a couple of questions:

  1. How do I see the code used by the flutter plugin to build my application? For extensions there is a snapcraft option expand-extensions, is there something similar for plugins?
  2. How do I enable debug/logs for the flutter application in snap?
  3. Is there any tricks to debug the application quickly? Currently I re-do ‘snapcraft’, ‘snap install’ and then run the application, but this is a relatively slow cycle.

My snapcraft.yaml:

name: intercom-test
base: core22
version: "0.1"
summary: My flutter application using media_kit, web_rtc, livekit
description: |
  Trying to package application as snap and get it to work :)

grade: stable
confinement: devmode


    command: intercom_test
    plugs: [home, desktop, desktop-legacy, network, network-bind, opengl, x11, audio-playback]
    extensions: [gnome]

    source: .
    plugin: flutter
    build-packages: [libmpv-dev]
    flutter-target: lib/main.dart
      - libmpv1
      - libblas3

Hi @Charlee .

Can you report the bug in this chat (copy and paste the errors ) ?

If your host system matches the base (i.e. in the above case you’d need 22.04 for the core22 base) you can run snapcraft in --destructive-mode and use the snap try command inside the prime directory of your build, that saves you from installing the snap and gives a slightly faster turnaround time…

@baldeuniversel there is no errors, that is the problem. My application just crashes/freezes.

I am trying to figure out a way to get more information, which is why I want to find out how to enable debug logs for my application so I can start adding print statements.

@ogra Thanks :slight_smile: It doesn’t at the moment, system is still on 20.04 at the moment, but that is good to know! Maybe I should try to upgrade the system, or to build the flutter application on core20…

I think I will try to build flutter myself rather than use the plugin, so I have more control. I found this snapcraft.yaml: and will try to do the same on core20 and see what happens.

1 Like

I managed to do the flutter build with the ‘build-override’ step rather than the flutter plugin.

This successfully let me call ‘flutter build linux --debug’, rather than --release :slight_smile: The code that worked:

    source-tag: 3.16.3
    source-depth: 1
    plugin: nil
    override-build: |
      mkdir -p $CRAFT_PART_INSTALL/usr/bin
      mkdir -p $CRAFT_PART_INSTALL/usr/libexec
      cp -r $CRAFT_PART_SRC $CRAFT_PART_INSTALL/usr/libexec/flutter
      ln -s $CRAFT_PART_INSTALL/usr/libexec/flutter/bin/flutter $CRAFT_PART_INSTALL/usr/bin/flutter
      ln -s $SNAPCRAFT_PART_INSTALL/usr/libexec/flutter/bin/dart $SNAPCRAFT_PART_INSTALL/usr/bin/dart
      $CRAFT_PART_INSTALL/usr/bin/flutter doctor
      - clang
      - cmake
      - curl
      - libgtk-3-dev
      - ninja-build
      - unzip
      - xz-utils
      - zip
    override-prime: ''

    after: [flutter-git]
    source: .
    plugin: nil
    override-build: |
      # when building locally artifacts can pollute the container and cause builds to fail
      # this helps increase reliability for local builds
      flutter clean
      # work around pub get stack overflow #
      set +e
      dart pub get
      set -eux
      export BUILD_TYPE=debug

      flutter build linux --$BUILD_TYPE -v
      mkdir -p $CRAFT_PART_INSTALL/bin/
      ls build/linux/*/$BUILD_TYPE/bundle/*
      cp -r build/linux/*/$BUILD_TYPE/bundle/* $CRAFT_PART_INSTALL/bin/
      ls $CRAFT_PART_INSTALL/bin/
    build-packages: [libmpv-dev]
      - libmpv1 # Trying to resolve mpv dependency complaint, but not helping
      - libblas3 # Added because I got error loading when running snap
      - libmpv-dev

However, when I try to do the same for core20 I see that the environment variables are missing. What would be the equivalent of the variables CRAFT_PART_INSTALL and CRAFT_PART_SRC in core20? Or do I just do a more hard-coding approach? (using paths like… /root/parts/flutter-git/bin and such)

P.S. In general I have to say the documentation I have found on differences between versions seems a bit limited, any suggestions on where to look? Or do you advise to not try to build packages for older bases in general?


1 Like

Well, beyond the fact that they go out of support earlier there is always the context in which you will use the resulting snap…

If you target UbuntuCore with what you’re building you have to keep in mind that you will have to seed an additional base snap at image build time, which bumps up the footprint of the image and indeed means one more snap to care about during the lifetime of the device (and indeed this part of your image will stop getting security fixes 2y earlier than the rest)

I understand, it is probably best to just work on core22 and bump my system :slight_smile:

Just trying to play around a bit with different settings to get the hang of it all… :slight_smile:

But I think I can consider the current question solved as I am now getting debug logs

1 Like

FWIW, libblas3 doesn’t run its usual post-install script that puts a symlink where it needs to be to actually work in snaps.

The easiest way to work around that is by adding this to your part in the Snapcraft.yaml

      usr/lib/*-linux-gnu/blas/*: usr/lib/

Which should work for any architecture by just taking the .so files from the BLAS folder and putting them in the normal $LD_LIBRARY_PATH folders.

Alternatively you’d add the folder to $LD_LIBRARY_PATH but that involves more scripting for the same effective result.

1 Like