Snapcraft build fails on Ubuntu VM

snapcraft installs ok in an Ubuntu VM on my Mac but fails to build a gadget snap due to multipass failing:

Support for 'multipass' needs to be set up. Would you like to do it now? [y/N]: y
snapd is not logged in, snap install commands will use sudo
multipass 1.15.1 from Canonical✓ installed
Waiting for multipass...
Launching a VM.
launch failed: cannot connect to the multipass socket
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.
Apr 11 09:57:23 ubuntu systemd[1]: Started snap.multipass.multipassd.service - Service for snap application multipass.multipassd.
Apr 11 09:57:23 ubuntu multipassd[45048]: Using AppArmor support
Apr 11 09:57:23 ubuntu multipassd[45048]: Failed to enable AppArmor: AppArmor is not enabled
Apr 11 09:57:23 ubuntu multipassd[45048]: Starting dnsmasq
Apr 11 09:57:23 ubuntu multipassd[45048]: [45085] started: dnsmasq --keep-in-foreground --strict-order --bind-interfaces --pid-file --domain=multipass --local=/multipass/ --except-i>
Apr 11 09:57:23 ubuntu multipassd[45048]: 
                                          dnsmasq: directory /etc/resolv.conf for resolv-file is missing, cannot poll
Apr 11 09:57:23 ubuntu dnsmasq[45085]: directory /etc/resolv.conf for resolv-file is missing, cannot poll
Apr 11 09:57:23 ubuntu dnsmasq[45085]: FAILED to start up
Apr 11 09:57:23 ubuntu multipassd[45048]: dnsmasq died: Process returned exit code: 5
Apr 11 09:57:23 ubuntu multipassd[45048]: Caught an unhandled exception: dnsmasq died: Process returned exit code: 5
Apr 11 09:57:23 ubuntu systemd[1]: snap.multipass.multipassd.service: Main process exited, code=exited, status=1/FAILURE
Apr 11 09:57:23 ubuntu systemd[1]: snap.multipass.multipassd.service: Failed with result 'exit-code'.

I’m not very familiar with troubleshooting Multipass on MacOS, but are you able to launch VMs without involving snapcraft?

multipass launch core24

Trying that I get: launch failed: cannot connect to the multipass socket

I’m guessing that the VM I am using has some incompatibilities with the underlying OS but I’m not sure where to start.

https://documentation.ubuntu.com/multipass/en/latest/how-to-guides/install-multipass/ is a good starting point, there may be some additional steps needed to install.

Are you running on a Mac with Apple Silicon? Ie is your cpu an M1 or newer? If that is the case then, as you indicated that you’re running snapcraft inside an Ubuntu VM this might be your issue. Currently Apple Silicon macs cannot run nested virtualisation, which is needed for multipass to work within a vm.