Running Anbox on Raspberry Pi

Posted in linux, android

Intro

Anbox provides a userland rootfs, glue logic and kernel modules to run android applications on GNU/Linux.

By default it supports x86_64 architectures. I wanted to run some android APKs on my Raspberry PI 4, which comes with an armv7l kernel.

After a bit of tinkering I got it “running”, though it was quite unstable.

Don’t expect to run your favorite games with this on the PI, not yet anyway.

Prerequisites

  • A Raspberry Pi 4
  • A fast internet connection
  • A desktop/server to build android.img
  • Loads of patience

Chapter 1: PI Kernel from source

This is needed to get the matching kernel headers / Modules.symvers, so we can build binder/ashmem

$ sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/bin/rpi-source && sudo chmod +x /usr/bin/rpi-source && /usr/bin/rpi-source -q --tag-update
$ rpi-source
$ cd ~/linux
$ zcat /proc/config.gz > .config
$ make -j4 zImage modules dtbs
$ sudo cp arch/arm/boot/zImage /boot/kernel7l.img
$ sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
$ sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
$ sudo cp arch/arm/boot/dts/*.dtb /boot/

Reboot and verify with uname -a.

Chapter 2: binder_linux && ashmem kernel modules

  • Clone anbox-modules
  • Add #define CONFIG_ANDROID_BINDER_IPC_32BIT on top of binder/binder.c
  • Follow the install instructions

Chapter 3: Anbox from source

  • Clone anbox
  • Remove warning-as-error flags from CMakeLists.txt
  • Replace uint64_t with uint32_t in src/anbox/input/device.cpp, struct CompatEvent (for 32-bit android userland)
  • Build and sudo make install

Chapter 4: Anbox/android.img for armv7

This downloads ~ 40GB of sources and uses ~ 100GB of disk space. You need a powerful desktop for this step.

  • Follow instructions in anbox/build-android
  • Modify the heap size from dalvik.vm.heapsize=512m to dalvik.vm.heapsize=128m
  • Repack with mksquashfs

Chapter 5: Run anbox

$ sudo ANBOX_LOG_LEVEL=debug anbox container-manager --daemon --privileged --data-path=/var/lib/anbox
$ anbox session-manager --single-window --window-size=1024,768

Chapter 6: Enjoy the crashes

You should now have anbox running on your pi! Connect via adb and install APKs.