How to create snap for Pi3


I would like to build an snap for Pi3, any example for this?

Further more, Does I need to setup arm version of snapcraft tool?


You can use an UbuntuCore image on a Pi and run lxd containers on it to run snapcraft in them; you could use an Ubuntu Server preinstalled Pi image and just natively build there … (i’d recommend a Pi4 with USB3.1 SSD disk here, that is reasonably fast)

Alternatively you can use the service to build armhf/arm64 snaps fron git trees maintained on github.

There’s also snapcraft remote-build:

1 Like

oh, yeah, i totally forgot that we now have remote-build too …

Can i setup cross compiler environment on myself server? Because I not only build for Pi3, but also has other platform, I prefer to setup cross complier environment on my server.
can you share me the steps for this?

I create a demo project, the source code as below.

when I use command “snapcraft” to build snap, it report below error:
Failed to generate snap metadata: The specified command ‘demo’ defined in the app ‘demo’ does not exist or is not executable

when I use command “snapcraft --target-arch=armhf” to build snap, it reports below error:
NotImplementedError: The plugin used by ‘demo’ does not support cross-compiling to a different target architecture

root@652edbcfb660:~/demo# cat src/demo/Makefile

demo: demo.o
$(CC) -o demo demo.o

$(CC) -c demo.c

install: demo
install $^ $(PREFIX)/bin

rm demo demo.o -rf
root@652edbcfb660:~/demo# cat src/demo/demo.c
#include <stdio.h>
#include <syslog.h>
#include <unistd.h>

int main(void)
syslog(LOG_INFO , “02colin3\n”);
syslog(LOG_ERR, “03colin3\n”);
return 0;
root@652edbcfb660:~/demo# cat snap/snapcraft.yaml
name: demo
version: ‘0.1’
summary: demo
description: |
It is an dump snap

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

command: demo
daemon: simple

source: src/demo
source-type: local
plugin: make
override-build: |
artifacts: [demo]

@ogra @Saviq

Can you help to give some suggestions?


well, for very simple binaries with not many dependencies you can take a look at one of my gadget snaps on github like:

that works fine for simple things like u-boot or a kernel, or even a single-app binary without many build dependencies, if they accept stuff like the CROSS_COMPILE environment variable …

for more complex stuff i’d really suggest to go native and use something like a Pi4 with lxd container …

looks like the problem is when I define an “app” in snapcraft.yaml, snapcraft tool will try to executable the app before snap file generation, and the throw below error because the app bin file is ARM format. any idea?

Failed to generate snap metadata: The specified command ‘demo’ defined in the app ‘demo’ does not exist or is not executable

no, this has nothing to do with the architecture, it literally means what it says, the app is not where you defined in your command: in snapcraft.yaml or it misses the executable bit on the file …

yes, you are right, it is file missing… Thank you !