Invalid icon path '$SNAP/meta/gui/icon.png'


Recent automated review has failed with the error:

invalid icon path '$SNAP/meta/gui/icon.png'. Should either specify the basename of the file (with or without file extension), snap.<snap name>.<snap command>[.(png|svg)] or ${SNAP}/path/to/icon.(png|svg) lint-snap-v2_desktop_file_icon (hw-probe.desktop, $SNAP/meta/gui/icon.png)

Why? How to fix this?

Desktop file is:

[Desktop Entry]
Name=Hardware Probe
Comment=Probe for hardware and upload result to the Linux hardware database
Keywords=HW Probe;Hardware;Probe;


Fixed by adding install instructions for icon in snapcraft.yaml:

mkdir -p $SNAPCRAFT_PART_INSTALL/usr/share/icons/
cp -f <SRC>/icon-64x64.png $SNAPCRAFT_PART_INSTALL/usr/share/icons/hw-probe.png

And fixing a line in the desktop file:



Simply changing it to ${SNAP}/meta/gui/icon.png would likely have been sufficient.

The desktop file sanitisation routines in snapd only expand ${SNAP} and not $SNAP, so it is likely that your old icon line wasn’t being expanded correctly either. All that has changed is that the review tools have been updated to catch this mistake.


Snapcraft prefers that you don’t prefix with ${SNAP} any more. While it will work, the preferred method is to use /usr/share/icons/hw-probe.png when your icon is in that location by considering the snap root as /. This makes it easier to support unmodified desktop files from the upstream projects, where for example if you were to use autotools and set --prefix=/usr it will install the icons relative to /usr and set their location in the desktop file (provided the autotools project is configured to do so) with the path beginning with /usr and it will “just work”.


This is half true though, if you drop file under snap/{gui,hooks} snapcraft just passes them along as those are handcrafted and assumed to be correct.


In terms of the review-tools and the upcoming PR from @jamesh, meta/snap.yaml (as opposed to snapcraft.yaml), cannot use absolute paths. I understood that snapcraft will translate /usr/share/icons/hw-probe.png in the snapcraft.yaml into ${SNAP}/usr/share/icons/hw-probe.png in the resulting meta/snap.yaml. @daniel and @sergiusens - is this the case? I can adjust the message accordingly based on your feedback.


Yes, it’s a convenience that snapcraft handles / anchored paths. Internally under the hood it will add the ${SNAP} prefix.


I’ll adjust the error message and also explicitly check for $SNAP to make it easier to spot that mistake.


I said that wrong, I obviously meant the desktop files cannot use absolute paths for icons, not snap.yaml.