Problems creating a snap with Java JRE headless and ARM64/AARCH64

you will need to do a bit more here to make sure the foreign arches fully supported by the build environment … here is a (very hackish but for inspiration) example that would get you an arm64 java binary built on a PC:

name: javatest
base: core20
version: '0.1'
summary: test java
description: |
  test java

grade: stable
confinement: strict

architectures:
  - build-on: amd64
    run-on: arm64

apps:
  javatest:
    command: usr/lib/jvm/java-11-openjdk-arm64/bin/java
    environment:
      JAVA_HOME: $SNAP/usr/lib/jvm/java-8-openjdk-arm64
      PATH: $JAVA_HOME/bin:$PATH

parts:
  init-multiarch:
    plugin: nil
    override-pull: |
      # add foreign architecture to hosts apt setup
      dpkg --add-architecture arm64
      # wipe original sources.lists
      echo "" >/etc/apt/sources.list
      rm -rf /etc/apt/sources.list.d/*
      # add arm64 support
      cat > /etc/apt/sources.list << EOF
      deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal main restricted universe multiverse
      deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-updates main restricted universe multiverse
      deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports focal-security main restricted universe multiverse
      EOF
      # force arm64 as default apt arch
      echo 'APT::Architecture "arm64";' >/etc/apt/apt.conf.d/00default-arch
      apt update
  jre:
    after: [ init-multiarch ]
    plugin: nil
    stage-packages:
      - openjdk-11-jre-headless:arm64

(do never use that with --destructive-mode on an actual host, it really breaks the build environment for good)

if you want to ship some jar file etc from another part you should actually add parts before these two parts above, because many plugins (i.e. “dump”) will not work anymore after the modification that “init-multiarch” does …