Snapcraft 3, core18, and Desktop Apps

I’ve been using Snapcraft 3.x, Multipass, and the core18 base. For my terminal applications, this has been working just fine. Not so much for GUI apps.

The forum docs show how to use the desktop-gtk3 remote part (and others) when building desktop snaps. They provide all the right libraries and pieces needed to run the app. Even the useful desktop-launch command.

In the new Snapcraft 3, Multipass, core18 world, remote parts aren’t supported (according to the error message) so how do we go about building these desktop snaps now?

Yeah, this is unfortunate and needs documenting.

Do this:- (note the sed line is removing reference to the core18 base which causes snapcraft to run in ‘legacy’ mode, which will mean the snapcraft define line works (which won’t work if the base is there, causing snapcraft to work in 3.0 mode)).

alan@KinkPad-K450:~$ mkdir ~/snapcraft_legacy
alan@KinkPad-K450:~$ cd ~/snapcraft_legacy/
alan@KinkPad-K450:~/snapcraft_legacy$ snapcraft init
Created snap/snapcraft.yaml.
Go to https://docs.snapcraft.io/the-snapcraft-format/8337 for more information about the snapcraft.yaml format.
alan@KinkPad-K450:~/snapcraft_legacy$ sed -i '/core18/d' snap/snapcraft.yaml
alan@KinkPad-K450:~/snapcraft_legacy$ snapcraft define desktop-gtk3
Maintainer: 'Snapcraft community (https//forum.snapcraft.io)'
Description: Helpers for gtk2, gtk3, qt4 and qt5 or gnome-platform and glib minimal launchers.
It brings the necessary code and exports for binding and using those
desktop technologies in a relocatable fashion, enabling binding with
global desktop theme, icon theme, image caching, fonts, mimetype handlers
application global menu and gsettings integration.
It also brings basics ubuntu dependency packages.
.
Usage:
  1. add "after: [desktop-<technology>]" to your launcher:
     - gtk2, gtk3, qt4 and qt5 corresponds to their respective toolkit
       main dependencies and default choices.
     - gnome-platform is similar to gtk3 without the extra depends, it's
       meant to be used with the gnome platform which already includes those.
     - glib-only enables to compile mime types and gsettings infos. If you
       added your own graphical drivers, it will link them as well.
  2. prepend your command with "desktop-launch", like:
     commands: "desktop-launch foo" if foo is in $PATH. You can as well
     specify: "desktop-launch $SNAP/foo".
  3. add needed plugs to your application:
     - for graphical application:
       plugs: [x11 (or unity7 for appmenu integration)]. Think about adding
       opengl if you need hw acceleration.
     - if your application needs access to sound:
       plugs: [pulseaudio]
     - accessing to user's home directory:
       plugs: [home]
     - read/write to gsettings:
       plugs: [gsettings]
     - use of the shared platform snap content, first define the plug:
         plugs:
           gnome-3-26-1604:
             interface: content
             target: gnome-platform
             default-provider: gnome-3-26-1604:gnome-3-26-1604
       and then make your apps use it:
         plugs: [gnome-3-26-1604]
       Note that an empty "gnome-platform" directory will be created for you
       in your snap.


desktop-gtk3:
  build-packages:
  - build-essential
  - libgtk-3-dev
  make-parameters:
  - FLAVOR=gtk3
  plugin: make
  source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
  source-subdir: gtk
  stage-packages:
  - libxkbcommon0
  - ttf-ubuntu-font-family
  - dmz-cursor-theme
  - light-themes
  - adwaita-icon-theme
  - gnome-themes-standard
  - shared-mime-info
  - libgtk-3-0
  - libgdk-pixbuf2.0-0
  - libglib2.0-bin
  - libgtk-3-bin
  - unity-gtk3-module
  - libappindicator3-1
  - locales-all
  - xdg-user-dirs
  - ibus-gtk3
  - libibus-1.0-5
  - fcitx-frontend-gtk3

Take that bit at the end and paste it in as a part in your snap. Here’s that specific bit.

desktop-gtk3:
  build-packages:
  - build-essential
  - libgtk-3-dev
  make-parameters:
  - FLAVOR=gtk3
  plugin: make
  source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
  source-subdir: gtk
  stage-packages:
  - libxkbcommon0
  - ttf-ubuntu-font-family
  - dmz-cursor-theme
  - light-themes
  - adwaita-icon-theme
  - gnome-themes-standard
  - shared-mime-info
  - libgtk-3-0
  - libgdk-pixbuf2.0-0
  - libglib2.0-bin
  - libgtk-3-bin
  - unity-gtk3-module
  - libappindicator3-1
  - locales-all
  - xdg-user-dirs
  - ibus-gtk3
  - libibus-1.0-5
  - fcitx-frontend-gtk3
2 Likes

I’ll give that a try, thank you.

Thanks for this post, I had the exact same question.

I tried what was suggested in this post. When I attempt to run my snap, I get this message:

You need to connect this snap to the gnome platform snap.

You can do this with those commands:
snap install gnome-3-26-1604
snap connect openresizer:gnome-3-26-1604 gnome-3-26-1604

What am I doing wrong? My snapcraft.yaml is:

name: openresizer # you probably want to 'snapcraft register <name>'
base: core18 # the base snap is the execution environment for this snap
version: '1.0' # just for humans, typically '1.2+git' or '1.3.2'
summary: Batch image resizer with a GUI # 79 char long summary
description: |
  OpenResizer is an open-source batch image resizing software with a GUI.
  It is designed to be fast and easy-to-use.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

icon: gui/icon.png

architectures:
  - build-on: [amd64, i386]
    run-on: all


parts:

  desktop-gtk3:
    build-packages:
    - build-essential
    - libgtk-3-dev
    make-parameters:
    - FLAVOR=gtk3
    plugin: make
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: gtk
    stage-packages:
    - libxkbcommon0
    - ttf-ubuntu-font-family
    - dmz-cursor-theme
    - light-themes
    - adwaita-icon-theme
    - gnome-themes-standard
    - shared-mime-info
    - libgtk-3-0
    - libgdk-pixbuf2.0-0
    - libglib2.0-bin
    - libgtk-3-bin
    - unity-gtk3-module
    - libappindicator3-1
    - locales-all
    - xdg-user-dirs
    - ibus-gtk3
    - libibus-1.0-5
    - fcitx-frontend-gtk3


  main-part:
    # See 'snapcraft plugins'
    plugin: python
    python-packages:
      - pillow
    stage-packages:
      - python-gi
   
    

  openresizer:
    plugin: dump
    source: https://github.com/jrezai/openresizer.git
    source-type: git
    after: [desktop-gtk3]
    organize:
      glade_files: bin/glade_files


apps:
  openresizer:
    command: desktop-launch $SNAP/bin/openresizer.py
    plugs: [x11, unity7, pulseaudio, wayland, desktop, desktop-legacy, gsettings, home, removable-media]

I solved it by adding the following:

plugs:
 gnome-3-26-1604:
   interface: content
   target: gnome-platform
   default-provider: gnome-3-26-1604:gnome-3-26-1604


apps:
  openresizer:
    command: desktop-launch $SNAP/bin/openresizer.py
    plugs: [gnome-3-26-1604, x11, unity7, pulseaudio, wayland, desktop, desktop-legacy, gsettings, home, removable-media]

So now my snap doesn’t show that message anymore (although it’s still not working 100% in other ways). It now looks like this, in case any one else was having the same issue:

name: openresizer # you probably want to 'snapcraft register <name>'
base: core18 # the base snap is the execution environment for this snap
version: '1.0' # just for humans, typically '1.2+git' or '1.3.2'
summary: Batch image resizer with a GUI # 79 char long summary
description: |
  OpenResizer is an open-source batch image resizing software with a GUI.
  It is designed to be fast and easy-to-use.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

icon: gui/icon.png

architectures:
  - build-on: [amd64, i386]
    run-on: all


parts:

  desktop-gtk3:
    build-packages:
    - build-essential
    - libgtk-3-dev
    make-parameters:
    - FLAVOR=gtk3
    plugin: make
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: gtk
    stage-packages:
    - libxkbcommon0
    - ttf-ubuntu-font-family
    - dmz-cursor-theme
    - light-themes
    - adwaita-icon-theme
    - gnome-themes-standard
    - shared-mime-info
    - libgtk-3-0
    - libgdk-pixbuf2.0-0
    - libglib2.0-bin
    - libgtk-3-bin
    - unity-gtk3-module
    - libappindicator3-1
    - locales-all
    - xdg-user-dirs
    - ibus-gtk3
    - libibus-1.0-5
    - fcitx-frontend-gtk3



  main-part:
    # See 'snapcraft plugins'
    plugin: python
    python-packages:
      - pillow
    stage-packages:
      - python-gi
   
    

  openresizer:
    plugin: dump
    source: https://github.com/jrezai/openresizer.git
    source-type: git
    after: [desktop-gtk3]
    organize:
      glade_files: bin/glade_files
    prepare: |
      chmod +x bin/openresizer.py


plugs:
 gnome-3-26-1604:
   interface: content
   target: gnome-platform
   default-provider: gnome-3-26-1604:gnome-3-26-1604


apps:
  openresizer:
    command: desktop-launch $SNAP/bin/openresizer.py
    plugs: [gnome-3-26-1604, x11, unity7, pulseaudio, wayland, desktop, desktop-legacy, gsettings, home, removable-media]
1 Like