Flutter build error: unknown command "channel"

I previously used snapcore/action-build Github Action to build and it builds Flutter projects successfully. I migrated to snapcraft-multiarch-action as I need arm64 builds, but Flutter build seems to be broken:

...
 Run health check of "gtk-common-themes" snap                                   -
25hgtk-common-themes 0.1-52-gb92ac40 from Canonical✓ installed
Pulling flutter-extension 
+ flutter channel stable
error: unknown command "channel", see 'snap help'.
Failed to run 'override-pull': Exit code was 64.
Error: No snap files produced by build

Here is the full log: https://github.com/proninyaroslav/libretrack/runs/3414045204?check_suite_focus=true
Workflow file: https://github.com/proninyaroslav/libretrack/blob/master/.github/workflows/flutter_release_build.yml#L92
Snapcraft metadata: https://github.com/proninyaroslav/libretrack/blob/master/snap/snapcraft.yaml

It looks like the snap binary is failing to recognise that it is being called as a snap’s executable name (flutter). I don’t understand why this would be, and whether it is a problem of my container or not.

Can you run with SNAPD_DEBUG=1 ?

@diddledani
Is it possible to pass SNAPD_DEBUG=1 inside the container?

@ijohnson does this need to be passed when starting snapd or when calling flutter? in either case it’s not easy to hijack because the flutter extension adds the bits that call the flutter executable which means we can’t rewrite it without removing the extension and inserting all its bits manually; and snapd is started automatically by systemd.

When calling the /usr/bin/snap binary

This is only possible inside the container. @diddledani

I’ve been unable to reproduce the issue to attempt to diagnose. You can add the SNAP_DEBUG=1 environment variable by expanding the extensions with snapcraft expand-extensions. Copy the output into the snapcraft.yaml file replacing the content, after taking a backup. Then edit the file to add to the parts.flutter-extension the following:

    build-environment:
      - SNAP_DEBUG: '1'

Finally re-run the build and see if there’s any helpful output from snapd.

ok, I’ve managed to recreate the scenario with the appropriate debug variable set:

snapd is not logged in, snap install commands will use sudo
flutter 0+git.a3e8013 from Flutter Team✓ installed
snapd is not logged in, snap install commands will use sudo
gnome-3-28-1804 3.28.0-19-g98f9e67.98f9e67 from Canonical✓ installed
snapd is not logged in, snap install commands will use sudo
gtk-common-themes 0.1-52-gb92ac40 from Canonical✓ installed
Pulling flutter-extension 
+ env SNAP_DEBUG=1 flutter channel stable
error: unknown command "channel", see 'snap help'.
Failed to run 'override-pull': Exit code was 64.

Well that was helpful, @ijohnson :slight_smile:

Edit: d’oh I misspelled the variable name - SNAPD not SNAP! :woman_facepalming:

Edit 2: only one line of output of use:

snapd is not logged in, snap install commands will use sudo
flutter 0+git.a3e8013 from Flutter Team✓ installed
snapd is not logged in, snap install commands will use sudo
gnome-3-28-1804 3.28.0-19-g98f9e67.98f9e67 from Canonical✓ installed
snapd is not logged in, snap install commands will use sudo
gtk-common-themes 0.1-52-gb92ac40 from Canonical✓ installed
Pulling flutter-extension 
+ env SNAPD_DEBUG=1 flutter channel stable
2021/08/31 11:03:51.647365 tool_linux.go:204: DEBUG: restarting into "/snap/snapd/current/usr/bin/snap"
error: unknown command "channel", see 'snap help'.
Failed to run 'override-pull': Exit code was 64.

ok, it’s not specific to snapcraft executing the flutter command. I can reproduce it in an arm64 container running through qemu-user emulation. However, running snap run flutter succeeds, where /snap/bin/flutter fails.