Creating snap for Ubuntu 16.04 armhf

Hi everyone,

I want to create a snap for an OLIMEX which run Ubuntu 16.04 LTS and has a armhf processor.
I never do a snap before so with tutorials online I manage to do something which works in my Ubuntu VM on my computer (amd64). But when I tried to cross compile my snap to armhf, I get stuck… Here is my snapcraft.yaml file:

name: configure-iot
version: '0.0.1'
summary: Configuration script for IOTR
description: |
 This script allows user to configure the IOTR from Itron. 
base: core
grade: stable
confinement: strict
architectures:
  - build-on: all
    run-on: armhf

apps:
  configure-iot:
    command: bin/hello
    plugs: [home,network-bind]

parts:
  configure-iot:
    plugin: python
    python-version: python3
    source: .
    stage-packages: [ncbi-blast+]

So as you can see in this file, I change the “run-on” parameter. The problem is it didn’t work when I tried to use it on my armhf device and I get this strange issue:

dev@ssniotr:~$ configure-iot
/snap/configure-iot/x1/usr/bin/python3: 1: /snap/configure-iot/x1/usr/bin/python3: cannot open y:: No such file
/snap/configure-iot/x1/usr/bin/python3: 1: /snap/configure-iot/x1/usr/bin/python3: ELF: not found
/snap/configure-iot/x1/usr/bin/python3: 1: /snap/configure-iot/x1/usr/bin/python3: ????$: not found
/snap/configure-iot/x1/usr/bin/python3: 1: /snap/configure-iot/x1/usr/bin/python3: ?+??،Q
P@??F??@???B? @?@??SA?
?Q???!??
?QP: not found
/snap/configure-iot/x1/usr/bin/python3: 2: /snap/configure-iot/x1/usr/bin/python3:: not found
/snap/configure-iot/x1/usr/bin/python3: 3: /snap/configure-iot/x1/usr/bin/python3: ?@???: not found
/snap/configure-iot/x1/usr/bin/python3: 4: /snap/configure-iot/x1/usr/bin/python3: Syntax error: “(” unexpected

I tried a lot of thinks such as:

  • Try to build on a Raspberry Pi 3 B+ with Raspbian Buster --> It didn’t work because it was a 32-bits distribution
  • Try to build with Multipass on a Raspberry Pi 3 B+ with Ubuntu 20.04 LTS Server 64-bits --> It didn’t work because I receive this error :

ubuntu@ubuntu : ~/configure-iot/snap $ snapcraft
Launching a VM.
launch failed: Internal error: qemu-system-x86_64 failed getting vmstate (Process returned exit code: 1) with output:
qemu-system-aarch64: -nographic: No machine specified, and there is no default
Use -machine help to list supported machines
An error occurred with the instance when trying to launch with ‘multipass’: returned exit code 2.
Ensure that ‘multipass’ is setup correctly and try again.

  • Try to build with lxd on a Raspberry Pi 3 B+ with Ubuntu 20.04 LTS Server 64-bits --> It didn’t work because I receive this error :

ubuntu@ubuntu : ~/configure-iot/snap $ snapcraft --use-lxd
The LXD provider is offered as a technology preview for early adopters.
The command line interface, container names or lifecycle handling may change in upcoming releases.
Launching a container.
An error occurred with the instance when trying to launch with ‘LXD’: Create instance: Requested architecture isn’t supported by this host.
Ensure that ‘LXD’ is setup correctly and try again.

  • Tried to install snapcraft on the Olimex (my armhf device) --> Not working because I got this message:

dev@ssniotr:/home/dev$ sudo snap install snapcraft
error: cannot install “snapcraft”: Post
https://api.snapcraft.io/v2/snaps/refresh: dial tcp: lookup
api.snapcraft.io on 127.0.0.1:53: server misbehaving

Have you an idea to compile for armhf ? or to solve one of these issues ?

Thanks

you really want

architectures: 
  - build-on: armhf 
    run-on: armhf

(or even omit the run-on since the build-on implies it)
and then build your snap natively on armhf, else you end up with x86 binaries inside the package and will get exec format errors …

there are no easy ways to cross-build snap packages (except for i.e. kernels or bootloaders that have no further dependencies) you need to build them on the target architecture …

the best way is to simply use https://build.snapcraft.io, that will build all architectures for you …

It takes more time to build… But it works. The only problem I was there is the fact I couldn’t download the snap on my Olimex or on my Raspberry… I had to use my Ubuntu 20.04 and download the snap with:

UBUNTU_STORE_ARCH=armhf snap download iotr-configuration --beta

And then copy it on the Olimex

1 Like