Skip to content

Repository files navigation

meta-android-4-linux

Yocto layer for a4l, which runs unmodified Android apps as Wayland clients on a Linux system: no emulator, no device image.

It targets wrynose, for x86_64 and aarch64, with glibc.

What is in it

Recipe Builds From
a4l the a4l executable, at a commit after release 0.1.0 source, in Yocto
a4l-skia the Skia a4l is pinned to (chrome/m150), as a static prefix in the sysroot source, in Yocto
a4l-aosp-runtime ART, the framework jars, the bionic runtime, a CA store and the a4l-run launcher a tarball you stage from an AOSP tree
a4l-keyring an unlocked Secret Service keyring for AndroidKeyStore; needs meta-gnome this layer
packagegroup-a4l pulls in a4l and a4l-aosp-runtime, and recommends packagegroup-a4l-services
core-image-a4l a Weston image with packagegroup-a4l
packagegroup-a4l-services the host daemons a4l's service backends talk to (A4L_SERVICES)

a4l needs a host ART build and the framework from an AOSP tree at android-13.0.0_r84. That is a Soong build and Yocto does not do it, so a4l-aosp-runtime packages its outputs from a tarball. a4l and a4l-skia build with no AOSP tree on the build machine. Without the staged files a4l builds with no native thread attach, and the executable alone prints its version and module list and cannot run an app.

Dependencies

  • openembedded-core, wrynose
  • meta-openembedded/meta-oe (sdbus-c++, pugixml; bubblewrap, optional)
  • optional: meta-openembedded/meta-multimedia for the pipewire and libcamera PACKAGECONFIGs of a4l
  • optional: meta-openembedded/meta-gnome for a4l-keyring

The clang toolchain is openembedded-core's. a4l-skia is built with it; a4l is built with the default toolchain.

DISTRO_FEATURES needs wayland, and with the default PACKAGECONFIG also vulkan and opengl.

Use

bitbake-layers add-layer .../meta-android-4-linux
bitbake a4l            # the executable and its Skia

To run apps on the target, stage the runtime once per architecture and tell the build where the tarballs are:

# on the machine that has the AOSP tree, with an a4l checkout at A4L_SRCREV
git -C a4l checkout c58424d701e86ffc5d1e51d59ab052e3b11e66d5   # A4L_SRCREV
scripts/a4l-stage-aosp-runtime.sh --arch aarch64 --a4l a4l --aosp /path/to/aosp \
    --webview --boot-image --out /srv/a4l/a4l-aosp-runtime-aarch64.tar.zst
scripts/a4l-stage-aosp-runtime.sh --arch x86_64 --a4l a4l --aosp /path/to/aosp \
    --webview --boot-image --out /srv/a4l/a4l-aosp-runtime-x86_64.tar.zst

Beside each tarball the script writes a4l-aosp-runtime-<arch>.bionic-offsets.h, the layout of bionic's thread block in that tree. Keep the two together in A4L_AOSP_RUNTIME_DIR: a4l is compiled against the header, and a4l-aosp-runtime refuses a tarball whose manifest does not name it. The script prints the tarball's sha256 when it is done.

# local.conf
A4L_AOSP_RUNTIME_DIR = "/srv/a4l"
# optional: accept only these tarballs
A4L_AOSP_RUNTIME_SHA256:aarch64 = "<sha256 the script printed>"
A4L_AOSP_RUNTIME_SHA256:x86-64 = "<sha256 the script printed>"

The tarball is a local file with no checksum in the recipe, so by default whatever is at that path is packaged. With A4L_AOSP_RUNTIME_SHA256 set the build fails on a tarball with another sum.

bitbake core-image-a4l

core-image-a4l is core-image-weston's base (Weston, a terminal, ssh) with packagegroup-a4l and 1 GiB of extra room for apps. It needs wayland vulkan opengl pam in DISTRO_FEATURES. For another image, add the packagegroup:

IMAGE_INSTALL:append = " packagegroup-a4l"

Until A4L_AOSP_RUNTIME_DIR is set, a4l-aosp-runtime is skipped at parse time and says why.

On the target, in a Wayland session:

a4l-run app.apk --present
a4l-run app.apk --present --ivi-surface-id=9000     # ivi-shell

a4l-run runs a4l run app.apk --vm=art --runtime=/usr/lib/a4l: a4l takes ART, the framework, its JNI libraries, the boot image, the bionic side and the WebView from the installed tree, and keeps any of those variables you set. When the machine has no /system, a4l gives the app a root of its own with the tree's system/ there, which a WebView and Flutter apps need. a4l-run adds ACL_PRESENT_GPU=1 unless you set it.

What the AOSP tree has to have built

The staging is a4l's own tools/stage-runtime.sh, which writes the layout these recipes read; scripts/a4l-stage-aosp-runtime.sh calls it with the file names the recipes look for and prints the tarball's sha256. It only reads the tree, and names everything the tree lacks before it writes anything.

  • Both architectures: lunch aosp_x86_64-eng, host ART (m build-art-host), the framework boot jars, framework-res, the target's fonts, and bionic. The jars and data are architecture-independent and come from this one build.
  • x86_64: libandroid_runtime, and a4l's libacl_graphics_jni and libacl_gles_jni in out/host/linux-x86/lib64 (a4l tools/aosp/graphics_jni, tools/aosp/gles_jni).
  • aarch64: the linux_glibc_arm64 outputs of a4l's tools/aosp/glibc-arm64/README.md, both lists in it, and the linux_bionic_arm64 bionic outputs.

a4l's two dex jars (aclshims.jar, hostboot.jar) and its bionic-side libraries are built from the a4l checkout you give the script, so they match the executable. The tarball records that commit, and the recipe refuses a tarball staged from another commit than A4L_SRCREV (A4L_AOSP_RUNTIME_STRICT = "0" turns that into a warning). libacl_graphics_jni.so and libacl_gles_jni.so are taken as the AOSP tree last built them, from a copy of a4l's tools/aosp/graphics_jni and gles_jni. Each carries a stamp of the sources it was compiled from, and the staging stops if that is not the stamp of the checkout's sources: run a4l's tools/sync-aosp-jni.sh and build the two libraries in the tree again. The MANIFEST records both stamps.

No CA store is staged. stage-runtime.sh can make one from the staging machine's roots (--cacerts); the recipe builds the store from the image's own roots and replaces one that is in the tarball.

The tarball has a layout version in its MANIFEST, and the recipe reads layout 3 only. A tarball of another layout is refused with "stage it again".

Variables

Variable Default
A4L_SRCREV c58424d7, after v0.1.0 the a4l commit built; set in conf/layer.conf
A4L_AOSP_RUNTIME_DIR unset directory holding a4l-aosp-runtime-<arch>.tar.zst and .bionic-offsets.h
A4L_AOSP_RUNTIME_STRICT 1 refuse a tarball from another a4l commit
A4L_AOSP_RUNTIME_SHA256 unset sha256 the tarball must have; set it per architecture
A4L_FONTS_CORE three faces the font files of a4l-aosp-runtime-fonts-core; see "Fonts at run time"
A4L_FILE_CHOOSER portal portal or zenity: what answers an app's file picker; see "Service backends at run time"
A4L_SERVICES by DISTRO_FEATURES the daemons of packagegroup-a4l-services; see "Service backends at run time"
A4L_RUNTIME_DIR /usr/lib/a4l where the runtime is installed; a boot image is tied to it (--prefix)

Moving A4L_SRCREV means moving the three SRCREVs beside it in a4l_git.bb to the revisions in that commit's subprojects/*.wrap, the Skia revisions in a4l-skia_150.bb if third_party/skia/METADATA changed, and staging the tarballs again.

PACKAGECONFIG of a4l

Each PACKAGECONFIG sets one of a4l's Meson feature options to enabled or disabled and adds its dependency. A part that is on and whose dependency is missing fails at configure.

Default: automotive skia gl dmabuf-codec alsa gstreamer sdbus secret crypto.

skia the Ganesh Vulkan present path (ACL_PRESENT_GPU=1); without it a4l presents through wl_shm
gl host EGL and GLES: GLSurfaceView, SDL2, Unity, libGDX
dmabuf-codec hardware video decode (V4L2; OpenMAX and VA-API where the device has them)
gstreamer video decode through the highest-ranked installed GStreamer decoder
ffmpeg software decode and SoundPool. Off by default: the ffmpeg recipe needs LICENSE_FLAGS_ACCEPTED += "commercial"
alsa, pipewire audio output; pipewire needs meta-multimedia
libcamera cameras; needs meta-multimedia
sdbus every D-Bus backend: network, Bluetooth, battery, storage, location, notifications, portals; see "Service backends at run time"
secret AndroidKeyStore on the Secret Service; see "The keystore at run time"
crypto APK signature verification with OpenSSL's libcrypto
drm-cxx KMS scanout sink of the split-process path
automotive the automotive profile (-Dprofile_automotive)

Service backends at run time

sdbus links a4l to D-Bus and nothing else. Each Android service is answered from a host daemon that a4l looks for when an app starts; with the daemon absent the app is told there is none (no Bluetooth adapter, no network, no battery), and a4l logs the backend it chose. packagegroup-a4l-services installs the daemons named in A4L_SERVICES, and packagegroup-a4l recommends it.

A4L_SERVICES Package Android side Bus In the default
bluetooth bluez5 android.bluetooth system with bluetooth in DISTRO_FEATURES
zeroconf avahi-daemon android.net.nsd system with zeroconf in DISTRO_FEATURES
battery upower BatteryManager system yes
power-profiles power-profiles-daemon power-save mode system no
storage udisks2 removable volumes system with polkit
location geoclue LocationManager system yes
gpsd gpsd LocationManager, with ACL_LOCATION=gpsd TCP 2947 no
portal xdg-desktop-portal open a link or mail, file pickers (Open, Save As), dark/light, device permissions session with polkit
keyring a4l-keyring AndroidKeyStore session with meta-gnome
pipewire pipewire wireplumber audio, with ACL_AUDIO=pipewire no; meta-multimedia
networkmanager, connman ConnectivityManager, WifiManager system no

Network. a4l reads network state from the daemon that already runs the device's network: ConnMan, NetworkManager or systemd-networkd, the first it finds in that order (ACL_NET_BACKEND names one). The default installs none of them, because an image has made that choice and two of them fight over the interfaces; systemd-networkd comes with systemd. Only the NetworkManager backend tells an app about Wi-Fi (SSID, signal, link speed); under the others Wi-Fi reads as off. An app that looks for its devices only on Wi-Fi can be shown a wired link as Wi-Fi with ACL_NET_WIRED_AS_WIFI=1 (a4l docs/pi-network.md).

Not chosen here. xdg-desktop-portal needs a backend for the desktop in use (xdg-desktop-portal-gtk in meta-gnome, -wlr in meta-multimedia). Notifications need a notification daemon on the session bus, which is the shell's. The session-bus rows need a4l to run in the user's session, as the keystore does.

File pickers. An app's Open, Attach or Save As goes to the portal's file chooser by default, and is answered as cancelled where there is no portal. On a bare compositor such as core-image-a4l's Weston, build a4l to run zenity instead (zenity is in meta-gnome):

A4L_FILE_CHOOSER = "zenity"

Set the list in local.conf to change it, for example a head unit on ConnMan with a GNSS receiver:

A4L_SERVICES = "bluetooth zeroconf connman gpsd keyring"

The keystore at run time

secret links libsecret, which is only the client side. An app's AndroidKeyStore keys persist when a Secret Service provider is on the user's session bus with its default keyring unlocked. Otherwise a4l keeps them in memory and says so when the app starts:

keystore backend: secret-service (login keyring)     keys persist
keystore backend: memory (non-persistent)            keys are lost at exit

An app that registers a device key (a messenger) then has to sign in again at every start. A board that boots straight to a compositor has no login that would create and unlock a keyring, so this layer has a4l-keyring:

  • it is in dynamic-layers/gnome-layer and exists when meta-gnome is in bblayers.conf (which needs meta-networking and meta-python); packagegroup-a4l then recommends it;
  • it depends on gnome-keyring and installs a systemd user unit, a4l-keyring.service, enabled for every user, that runs gnome-keyring-daemon --replace --unlock --components=secrets with the password in ~/.config/a4l/keyring-pass;
  • with no such file it writes a random password on the first run, mode 0600. Write the file yourself first (no trailing newline) to choose the password.

It needs systemd and pam in DISTRO_FEATURES, and a4l has to run in that user's session: XDG_RUNTIME_DIR set and DBUS_SESSION_BUS_ADDRESS naming the same bus. To check:

busctl --user get-property org.freedesktop.secrets \
    /org/freedesktop/secrets/collection/login org.freedesktop.Secret.Collection Locked

b false is an unlocked keyring. Any other Secret Service provider works in place of gnome-keyring. On a board with nobody at its screen set ACL_KEYRING_PROMPT=0, so that a locked keyring does not hold the app's start on an unlock prompt. ACL_KEYSTORE_BACKEND=memory forces the memory backend. a4l's docs/pi-keyring.md has the manual steps and what the password protects.

Fonts at run time

Android code takes its fonts from fixed paths, not from fontconfig. The framework reads /system/etc/fonts.xml for the families there are, and a native engine (Flutter's Skia) reads the same file and takes each face it names from /system/fonts and /fonts. With no /system, or with a family whose face is missing, an app runs and draws no text, and Chromium's WebView crashes on a worker thread when it reads the fonts.

  • The tree is installed at /usr/lib/a4l/system. By default a4l puts it at /system, /fonts and /apex/com.android.tzdata for the app, in a root of the app's own (as bubblewrap does), when the machine has no /system/etc/fonts.xml; the root file system has no Android paths. As a user other than root that needs unprivileged user namespaces in the kernel. PACKAGECONFIGs of a4l-aosp-runtime:

    rootfs-links installs a4l-aosp-runtime-rootfs-links: /system, /fonts and /apex/com.android.tzdata are links in the root file system, and a4l makes nothing. For a kernel without user namespaces.
    bubblewrap installs bwrap, which a4l-run uses for ACL_SANDBOX_UID (the app under another uid). Not needed for /system.
    PACKAGECONFIG:pn-a4l-aosp-runtime = "rootfs-links"
    

    No DISTRO_FEATURES entry says whether the kernel has unprivileged user namespaces, so it cannot be derived; set it in the distro or machine configuration that knows the kernel.

  • a4l-aosp-runtime-fonts-core, a hard dependency, holds fonts.xml (a4l's tools/aosp/fonts-min.xml) and the faces it names: the default and sans-serif family, serif and monospace (A4L_FONTS_CORE). The build fails if fonts.xml has no sans-serif family or names a face that is missing, empty, or outside that package.

  • a4l-aosp-runtime-fonts-extra (recommended, about 75 MB) is the rest of AOSP's system/fonts: other scripts, CJK, emoji.

  • a4l says at start when it cannot provide /system, and why.

a4l run --runtime=/usr/lib/a4l started without a4l-run gets the same /system.

Certificates at run time

Android code does not read the system's trust bundle. conscrypt (every Java HTTPS connection, and WebView) reads one PEM per root from $ANDROID_ROOT/etc/security/cacerts; Dart and an app's own native TLS read /system/etc/security/cacerts. Without that store every HTTPS connection an app makes is refused ("Trust anchor for certification path not found").

  • a4l-aosp-runtime builds the store from the ca-certificates recipe, the roots the image itself trusts, and installs it at /usr/lib/a4l/system/etc/security/cacerts. It is in the package, so it is there on a read-only root file system and needs nothing run at first boot.
  • It installs /etc/ca-certificates/update.d/a4l-cacerts, a hook of update-ca-certificates. A root added on the target (a .crt under /usr/local/share/ca-certificates, then update-ca-certificates) is added to the Android store too, and a removed one is removed. On a read-only root file system the hook says so and leaves the store as built; add the root at build time instead, to the ca-certificates recipe.
  • It depends on ca-certificates, which brings the openssl command the hook uses. What a4l does on the host side of an app, such as GStreamer or FFmpeg fetching a stream, trusts the system bundle and not the Android store.
  • A certificate an app's user installs is not supported: there is no user-added store.

Two things outside this layer decide whether a valid certificate is accepted:

  • The clock. A board with no battery-backed clock starts in the past and every certificate is "not yet valid" until the time is set. Have time synchronization in the image (systemd-timesyncd is in systemd's default PACKAGECONFIG) and working before an app starts.
  • APK signatures are checked against the certificate in the APK, with libcrypto.so.3 (crypto PACKAGECONFIG). No CA store is involved.

Notes

  • The wayland-cxx-scanner code generator runs while a4l compiles. The a4l recipe builds it for the build machine from the revision a4l pins, and does not use a wayland-cxx-scanner-native recipe from another layer.
  • a4l-skia is built with clang (TOOLCHAIN = "clang") and the distribution's C++ runtime, with the GN arguments of wayland-cxx-scanner's scripts/build-skia.sh. It installs nothing on the target.
  • a4l is built with the distribution's default toolchain on both architectures. Release 0.1.0 does not build that way: GCC 15 does not link its arm64 build, and an optimized build crashes in the first app library that calls GetEnv. Both are fixed at A4L_SRCREV (a4l PRs #413 and #412).
  • The runtime tarball is prebuilt. stage-runtime.sh puts the NOTICE files of seven AOSP projects in it under licenses/ (ART, bionic's libc, libcore, frameworks/base, conscrypt, ICU and the Roboto fonts), and the recipe's LIC_FILES_CHKSUM is on those. That is most of what the tarball is built from and not all of it: collect the remaining notices from the AOSP tree before you ship an image with it.
  • No JDK is needed to build. a4l includes jni.h and jvmti.h, which upstream takes from the build machine's JDK; the recipe passes AOSP's OpenJDK headers at the pinned revision with -Djni_include. --vm=jvm is compiled in but its framework classes are not built, and it would need a JRE on the target; --vm=art is what a4l-run uses.
  • To attach an app's native threads to bionic, a4l builds a bionic thread block by hand and needs its layout, which differs by architecture and is measured from bionic's private headers. The staging measures it (a4l's tools/gen-bionic-offsets.sh) and the recipe passes the header with -Dbionic_offsets and -Dbionic_attach=enabled, so nothing on the build machine is read for it. With A4L_AOSP_RUNTIME_DIR unset, a4l is built with -Dbionic_attach=disabled: an app whose native code starts threads does not run on it.

What has been tested

Built on wrynose with openembedded-core, meta-poky and meta-oe, for qemuarm64 and qemux86-64: a4l, a4l-skia, a4l-aosp-runtime, packagegroup-a4l and core-image-a4l, with the default PACKAGECONFIGs and tarballs staged with --webview --boot-image.

Run, x86_64 only: core-image-a4l in QEMU with KVM, two apps from F-Droid started with a4l-run app.apk --present in the Weston session. A Java-only app (a clock) and a WebView app (a map) both drew, and the map took input. That exercises a4l-run, the /system a4l makes, the fonts under it, the Vulkan present path and the WebView. Earlier runs used a bubblewrap namespace for /system, which the image no longer installs by default.

Not tested:

  • aarch64 has been built and not run.
  • Whether the ART boot image is used, the update-ca-certificates hook, and an HTTPS connection from Java code.
  • a4l-keyring has not been built; the test build had no meta-gnome.
  • The rootfs-links PACKAGECONFIG, and the pipewire, libcamera, ffmpeg and drm-cxx PACKAGECONFIGs of a4l, have not been built.

Running the image in QEMU

a4l presents through Vulkan and needs a device that exports dma-bufs. Under runqemu the guest has none, and an app stops at acl-gpu: createDevice fail: the QEMU that openembedded-core builds has a virglrenderer without Venus. A host QEMU that has it works, with the image's kernel and root file system (QEMU 10.2 here, on a Mesa host driver):

zstd -d core-image-a4l-qemux86-64.rootfs.ext4.zst -o rootfs.ext4
qemu-system-x86_64 -enable-kvm -cpu host -smp 4 -m 4096 \
    -object memory-backend-memfd,id=mem1,size=4G \
    -machine q35,i8042=off,memory-backend=mem1 \
    -device virtio-vga-gl,hostmem=4G,blob=true,venus=true \
    -display gtk,gl=on \
    -drive file=rootfs.ext4,if=virtio,format=raw -snapshot \
    -device virtio-net-pci,netdev=net0 \
    -netdev user,id=net0,hostfwd=tcp:127.0.0.1:2222-:22 \
    -usb -device usb-tablet -device usb-kbd \
    -kernel bzImage -append 'root=/dev/vda rw ip=dhcp console=ttyS0'

ACL_PRESENT_GPU=0 does not select another path: a4l reads any value as on, and its wl_shm path cannot show a real app.

Working on the layer

pip install oelint-adv shellcheck-py shfmt-py
scripts/lint.sh          # oelint-adv, shellcheck, then a shfmt diff
scripts/lint.sh --fix    # the same, and shfmt rewrites the shell scripts

oelint-adv only reports; its findings are fixed by hand. .oelint-constants.json names the layer's own variables for it.

License

The layer's metadata and scripts are MIT (COPYING.MIT). a4l is Apache-2.0.

Releases

Packages

Used by

Contributors

Languages