This method is not recommended anymore. These instructions are outdated.
Please use the
gnome-3-28extension instead. It does everything explained here automatically, and it contains a number of improvements. See GTK3 applications for a complete tutorial on how to use the extension.
GTK3 for snaps using
The GTK3 libraries are available in the
gnome-platform content snap and the snapcraft desktop helpers project provides the
desktop-launch script to configure the environment for GTK3.
First copy the definition of the
desktop-gnome-platform part from the Snapcraft Desktop Helpers
snapcraft.yaml into your Snapcraft recipe, in the
parts section. Change the
source property of this part to
parts: # This part installs the `desktop-launch` script which initialises desktop # features such as fonts, themes and the XDG environment. # # It is copied straight from the snapcraft desktop helpers project. Please # periodically check the source for updates and copy the changes. # https://github.com/ubuntu/snapcraft-desktop-helpers/blob/master/snapcraft.yaml # desktop-gnome-platform: source: https://github.com/ubuntu/snapcraft-desktop-helpers.git ... <please copy the rest of this part from the desktop helpers snapcraft.yaml> ...
desktop-launch script in the app command.
apps: audiocoder: command: bin/desktop-launch $SNAP/bin/audiocoder-gtk
Add the following plugs to connect your snap to the
gnome-platform snap for the GTK libraries and the
gtk-common-themes snap for common GTK themes. This uses the content interface to mount files of the
gnome-platform and the
gtk-common-themes snaps into your snap.
plugs: # GTK libraries gnome-3-28-1804: interface: content target: $SNAP/gnome-platform default-provider: gnome-3-28-1804 # Common GTK themes gtk-3-themes: interface: content target: $SNAP/data-dir/themes default-provider: gtk-common-themes icon-themes: interface: content target: $SNAP/data-dir/icons default-provider: gtk-common-themes sound-themes: interface: content target: $SNAP/data-dir/sounds default-provider: gtk-common-themes
Finally, connect your snap to the following desktop interfaces so it has permission to access desktop functionality.
apps: audiocoder: plugs: - desktop - desktop-legacy - wayland - x11 - unity7
Snapcraft will warn you several libraries are not found in the snap and the base snap as some of them are provided via the
gnome-platform content snap instead. Disregard those warning and only add the libraries that are really missing from the snap to the
apps: audiocoder: stage-packages: - gstreamer1.0-libav - gstreamer1.0-plugins-base - gstreamer1.0-plugins-good - gstreamer1.0-plugins-ugly - gstreamer1.0-pulseaudio - libappindicator3-1
Take a look at the GTK3 Demo snap for a fully working example.
GTK3 for snaps without
base property set
GTK3 applications should reference the
desktop-gtk3 remote part.
In this snippet, the remote part is referenced as a null part:
parts: desktop-gtk3: # You may optionally override parts of the remote part definition audiocoder:
snapcraft define _remote_part_name_ to check out the remote part’s definition.
In addition, the launcher script which sets up the environment should prepend the actual app command in the
apps section. Typically it’s also necessary to specify the full path to the target binary after the launcher.
apps: command: desktop-launch $SNAP/usr/bin/audiocoder-gtk plugs: [network, desktop, desktop-legacy]
These pre-defined parts do not automatically pull in all necessary GTK libraries, but the minimum required by most applications.
The developer is expected to list any further libraries as
stage-packages or additional