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:
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?
How do I enable debug/logs for the flutter application in snap?
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
environment:
LD_LIBRARY_PATH: ${SNAP}/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio
apps:
intercom-test:
command: intercom_test
plugs: [home, desktop, desktop-legacy, network, network-bind, opengl, x11, audio-playback]
extensions: [gnome]
environment:
LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/blas:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/lapack
parts:
intercom-test:
source: .
plugin: flutter
build-packages: [libmpv-dev]
flutter-target: lib/main.dart
stage-packages:
- libmpv1
- libblas3
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 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 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
The code that worked:
flutter-git:
source: https://github.com/flutter/flutter.git
source-tag: 3.16.3
source-depth: 1
plugin: nil
override-build: |
pwd
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
build-packages:
- clang
- cmake
- curl
- libgtk-3-dev
- ninja-build
- unzip
- xz-utils
- zip
override-prime: ''
flutter-with-dependencies:
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 # https://github.com/dart-lang/sdk/issues/51068#issuecomment-1396588253
set +e
dart pub get
set -eux
export BUILD_TYPE=debug
flutter build linux --$BUILD_TYPE -v
echo $CRAFT_PART_INSTALL
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]
stage-packages:
- libmpv1 # Trying to resolve mpv dependency complaint, but not helping
- libblas3 # Added because I got error loading libblas.so.3 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?
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)