Cannot access file /usr/share/alsa/alsa.conf if not using --devmode flag

Hello,

I am currently building an app using electron. But the problem is when I installed the snap version of it without using the --devmode flag it will have no sound and print some logs:

ALSA lib conf.c:3916:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM default
ALSA lib conf.c:3916:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM plug:default
ALSA lib conf.c:3916:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM default
ALSA lib conf.c:3916:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM plug:default

here’s my original snapcraft.yaml configuration:

name: productivity-timer
version: 1.0+git
summary: Beautiful Time Management App for Productivity inspired by Pomodoro Technique.
description: |
  This application is Free and OpenSource and has a lot of useful features that helps boost your productivity. It uses the method called Pomodoro Technique which is proven and tested to increase your overall productiveness.

base: core18
grade: stable
confinement: strict

architectures:
  - build-on: amd64

apps:
  productivity-timer:
    command: desktop-launch $SNAP/app/productivity-timer --no-sandbox
    extensions: [gnome-3-28]
    plugs:
      - desktop
      - desktop-legacy
      - home
      - x11
      - unity7
      - browser-support
      - network
      - gsettings
      - pulseaudio
      - opengl
    environment:
      TMPDIR:
        $XDG_RUNTIME_DIR
        # Fallback to XWayland if running in a Wayland session.
      DISABLE_WAYLAND: 1

parts:
  productivity-timer:
    source: app/
    plugin: nodejs
    nodejs-version: 12.14.1

    stage-packages:
      - libasound2
      - libgconf2-4
      - libnotify4
      - libnspr4
      - libnss3
      - libpcre3
      - libpulse0
      - libxss1
      - libxtst6

    override-build: |
      snapcraftctl build
      rm -rf $SNAPCRAFT_PART_INSTALL/app
      mkdir -p $SNAPCRAFT_PART_INSTALL/app
      mv dist/linux-unpacked/* $SNAPCRAFT_PART_INSTALL/app
    prime:
      - -node_modules

and try other solutions like this:

name: productivity-timer
version: 1.0+git
summary: Beautiful Time Management App for Productivity inspired by Pomodoro Technique.
description: |
  This application is Free and OpenSource and has a lot of useful features that helps boost your productivity. It uses the method called Pomodoro Technique which is proven and tested to increase your overall productiveness.

base: core18
grade: stable
confinement: strict

architectures:
  - build-on: amd64

apps:
  productivity-timer:
    command: desktop-launch $SNAP/app/productivity-timer --no-sandbox
    command-chain: [snap/command-chain/alsa-launch]
    extensions: [gnome-3-28]
    plugs:
      - desktop
      - desktop-legacy
      - home
      - x11
      - unity7
      - browser-support
      - network
      - gsettings
      - pulseaudio
      - opengl
    environment:
      TMPDIR:
        $XDG_RUNTIME_DIR
        # Fallback to XWayland if running in a Wayland session.
      DISABLE_WAYLAND: 1

layout:
  /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/alsa-lib:
    bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/alsa-lib

parts:
  alsa-mixin:
    plugin: nil
    source: https://github.com/diddlesnaps/snapcraft-alsa.git
    override-pull: |
      cat > asound.conf <<EOF
      pcm.!default {
          type pulse
          fallback "sysdefault"
          hint {
              show on
              description "Default ALSA Output (currently PulseAudio Sound Server)"
          }
      }
      ctl.!default {
          type pulse
          fallback "sysdefault"
      }
      EOF
      cat > alsa-launch <<EOF
      #!/bin/bash
      export ALSA_CONFIG_PATH="\$SNAP/etc/asound.conf"

      if [ -d "\$SNAP/usr/lib/alsa-lib" ]; then
          export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:\$SNAP/usr/lib/alsa-lib"
      elif [ -d "\$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/alsa-lib" ]; then
          export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:\$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/alsa-lib"
      fi
      export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:\$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio"

      # Make PulseAudio socket available inside the snap-specific $XDG_RUNTIME_DIR
      if [ -n "\$XDG_RUNTIME_DIR" ]; then
          pulsenative="pulse/native"
          pulseaudio_sockpath="\$XDG_RUNTIME_DIR/../\$pulsenative"
          if [ -S "\$pulseaudio_sockpath" ]; then
              export PULSE_SERVER="unix:\${pulseaudio_sockpath}"
          fi
      fi

      exec "\$@"
      EOF
      chmod +x alsa-launch
    override-build: |
      snapcraftctl build
      install -m644 -D -t $SNAPCRAFT_PART_INSTALL/etc asound.conf
      install -m755 -D -t $SNAPCRAFT_PART_INSTALL/snap/command-chain alsa-launch
    build-packages:
      - libasound2-dev
    stage-packages:
      - libasound2
      - libasound2-plugins

  desktop-glib-only:
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: glib-only
    plugin: make
    build-packages:
      - libglib2.0-dev
    stage-packages:
      - libglib2.0-bin

  productivity-timer:
    after: [alsa-mixin, desktop-glib-only]
    source: app/
    plugin: nodejs
    nodejs-version: 12.14.1

    stage-packages:
      - libasound2
      - libgconf2-4
      - libnotify4
      - libnspr4
      - libnss3
      - libpcre3
      - libpulse0
      - libxss1
      - libxtst6

    stage:
      - -usr/lib/x86_64-linux-gnu/libasound.so.2
      - -usr/lib/x86_64-linux-gnu/libasound.so.2.0.0

    override-build: |
      snapcraftctl build
      rm -rf $SNAPCRAFT_PART_INSTALL/app
      mkdir -p $SNAPCRAFT_PART_INSTALL/app
      mv dist/linux-unpacked/* $SNAPCRAFT_PART_INSTALL/app
    prime:
      - -node_modules

but still the app had no sound at all.

Maybe someone can help me with my problem. Thank you.

Here’s the link of the app I built https://github.com/roldanjrCodeArts9711/productivity-timer.

I don’t see alsa listed in your plugs. Have you tried adding and connecting that? Or audio-playback?

Thank you @alan_g. I added audio-playback to my plugs and It works for me.

name: productivity-timer
version: 1.0+git
summary: Beautiful Time Management App for Productivity inspired by Pomodoro Technique.
description: |
  This application is Free and OpenSource and has a lot of useful features that helps boost your productivity. It uses the method called Pomodoro Technique which is proven and tested to increase your overall productiveness.

base: core18
grade: stable
confinement: strict

architectures:
  - build-on: amd64

apps:
  productivity-timer:
    command: desktop-launch $SNAP/app/productivity-timer --no-sandbox
    extensions: [gnome-3-28]
    plugs:
      - audio-playback
      - desktop
      - desktop-legacy
      - home
      - x11
      - unity7
      - browser-support
      - network
      - gsettings
      - pulseaudio
      - opengl
    environment:
      TMPDIR: $XDG_RUNTIME_DIR
      # Fallback to XWayland if running in a Wayland session.
      DISABLE_WAYLAND: 1

parts:
  productivity-timer:
    source: app/
    plugin: nodejs
    nodejs-version: 12.14.1

    stage-packages:
      - libasound2
      - libgconf2-4
      - libnotify4
      - libnspr4
      - libnss3
      - libpcre3
      - libpulse0
      - libxss1
      - libxtst6

    override-build: |
      snapcraftctl build
      rm -rf $SNAPCRAFT_PART_INSTALL/app
      mkdir -p $SNAPCRAFT_PART_INSTALL/app
      mv dist/linux-unpacked/* $SNAPCRAFT_PART_INSTALL/app
    prime:
      - -node_modules
1 Like

Hi @roldanjr. Same problem here (but with anbox).

How, exacly you…?

(I’m linux fresh user :sweat_smile:) Can you help me with commands to fix alsa cannot access?

Thanks for your time! :+1: