Can't adopt-info or set icon

I’m having trouble doing two very simple things:

  1. Setting the snapcraft icon
  2. Adopting the metadata from an AppStream metadata file

My folder structure looks like this:

- /build
----icon.svg
----snapcraft.yaml
----metainfo.xml

My snapcraft.yaml looks like this:

adopt-info: metadata
icon: icon.svg

parts:
  metadata:
    plugin: dump
    source: .
    parse-info: [metainfo.xml]

The output when I include the icon is:

Specified icon 'icon.svg' does not exist.

The output when I attempt to do the adopt-info:

No metadata extracted from metainfo.xml                                                                                                                     
No metadata extracted from metainfo.xml                                                                                                                     
No metadata extracted from metainfo.xml  

I’m not sure why it prints that 3 times. Here’s the content of my metainfo.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
  <id>com.example.my-app</id> 
  <name>my-app</name>
  <summary>my-app</summary>
  <description>
    my-app
  </description>
  <launchable type="desktop-id">
    com.example.myapp
  </launchable>
  <releases>
    <release date="2024-01-01" version="1.0.0"/>
  </releases>
</component>

This seems like the most basic problem and I must be missing something obvious. I’m using snapcraft 8.x with lxd on Ubuntu 22.

As an option: you can put icon and desktop files needed for Gtk app into “snap/gui/” folder with the next filedir structure

snap
├── gui
│   ├── yoursnapname.desktop
│   └── yoursnapname.svg
└── snapcraft.yaml

and add Icon=${SNAP}/meta/gui/yoursnapname.svg line to desktop file (it surely works with png 512x512 icon and probably will work with .svg icon too)

So I figured them both out!

icon issue This was just an oversight as I expected. I was referencing icon.svg but it was called logo.svg and I just missed it. doh!

metadata issue I had to dig into the snapcraft source to solve this. Apparently your external metadata file must be named *.metadata.xml or *.appinfo.xml. Renaming that file myapp.metadata.xml allowed the adopt-info to work.

Here’s the relevant source code:

https://github.com/snapcore/snapcraft/blob/ffbdabf53de21606d9d12e15f16d4bca5e4423a5/snapcraft/meta/appstream.py#L93

if not relpath.endswith(".metainfo.xml") and not relpath.endswith(".appdata.xml"):
  return None

Why would snapcraft care what the name of the file is? It’s not like it it’s using the file afterwards (as far as I can tell) - it only uses the contents of the file.

Either way, it’s working now. Here’s the final config:

- /build
----icon.svg
----snapcraft.yaml
----myapp.metainfo.xml

And the yaml:

adopt-info: metadata
icon: icon.svg

parts:
  metadata:
    plugin: dump
    source: .
    parse-info: [myapp.metainfo.xml]
2 Likes