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

Hi Snap Community,

I am trying to create a snap which needs a Java Runtime Environment and should be working in a ARM64 Architecture.

The ideal Java package would be a Java JRE headless for aarch64/arm64.
I found this package from AdoptOpenJDK.

...
    grade: stable
    confinement: strict # use 'strict' once you have the right plugs and slots

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

    apps:
      snapname:

        environment:
          JAVA_HOME: $SNAP/usr/lib/jvm/java-11-openjdk-arm64


    parts:  
      snapname:
        stage-packages:
          - openjdk-11-jre-headless

So basically i think i am just not giving snapcraft the right package name for Java JRE headless arm64.

These are the stage package names i tried:
jdk-11.0.11+9-jre
openjdk-11-jre-headless
openjdk-11-jre-headless-arm64

Can anybody help me on this?

If anybody already created a snap which runs a Java Runtime Env on the ctrlX Device, i would appreciate help on this topic.

Here are more approaches for the task:

1.) snapcraft.yaml

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

part:
   mypart:
        ...
        stage-packages:
      - on amd64 to arm64: [openjdk-11-jre] #i tried also [openjdk-11] 

i assume this way snapcraft.yaml file takes the snap available in the snap-store: https://snapcraft.io/openjdk

Test results: Doesent create a java arm64 package but a java amd64 package.

2.) snapcraft.yaml

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

part:
   mypart:
     jre:
        plugin: dump
        source: https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.11%2B9/OpenJDK11U-jre_aarch64_linux_hotspot_11.0.11_9.tar.gz
        build-packages:
            - tar
            - gzip

Test results: it installs the right arm64 package into the ctrlX Core device. Though not working.

3.) implement from repository

#package-repositories:
#  - type: apt
#    architectures: [arm64]
#    formats: [deb, deb-src]
#    components: [main]
#    suites: [stable]
#    key-id: not found
#    url: http://ftp.de.debian.org/debian/pool/main/o/openjdk-11/openjdk-11-jre_11.0.11+9-1_arm64.deb

There is also a way to choose another repository or own hosted repository besides http://security.ubuntu.com/ubuntu/, which is the standard repo when snapcraft installs packages during building process. I guess.

Test results: no test results since i wasnt able to find the key-id (gpg) of the package.

NOTE:

I directed at any of these approaches the java jre into the $SNAP/usr/lib/jvm path. Which is the supposed place for a java runtime enviroment.

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 …