Jump to content

Waydroid

From postmarketOS Wiki
Note Consider using native Linux programs instead, see FAQ.

Waydroid is the modern approach to run Android apps on Linux. It is similar to Anbox, but it works with Wayland and is more performant. Waydroid is available in postmarketOS v21.12 and newer. Running Android apps on mobile Linux is still kind of experimental, so be prepared to deal with problems.

Requirements

CONFIG_RT_GROUP_SCHED=n

Make sure CONFIG_RT_GROUP_SCHED is disabled in your kernel config. On main and community devices it is already disabled by default, but some testing devices currently have it enabled by default. You can check your kernel by running this command:

$ zcat /proc/config.gz | grep CONFIG_RT_GROUP_SCHED

If this returns "CONFIG_RT_GROUP_SCHED=y", then you'll need to compile your kernel with it disabled and install the updated kernel with pmbootstrap. Follow the steps in kernel configuration. In menuconfig the option is in General setup ─> Control Group Support ─> CPU controller ─> Group scheduling for SCHED_RR/FIFO.

binder

The kernel needs to be build with the binder driver enabled. The linux-virt kernel package does not enable this module as in currently unusable.

Installation

$ sudo apk add waydroid

Additional steps, or else the container won't start:

$ sudo rc-update add cgroups default # optional
$ sudo rc-service cgroups start

Usage

After installation, the Waydroid session is configured to start automatically on boot.

Initialize Waydroid either by launching the graphical app, or with sudo waydroid init. This will download images and extract them, and will take some time to complete.

In order to run apps, the container needs to be started as well. (Apparently it should start automatically when running apps? Also it appears to take quite some time to start up.)

You can start the container and session as follows:

"Container" refers to the Android LXC container itself

$ sudo rc-service waydroid-container start

You can also let the container start on boot automatically:

$ sudo rc-update add waydroid-container default

"Session" refers to the Waydroid specific bits to integrate Android apps into your users environment (.desktop files etc). If it doesn't start up automatically on boot, you can launch it manually (and you have to do this if you stop the previously mentioned OpenRC service):

$ waydroid session start

Note that this command will not terminate after starting the session but will stay in the foreground, so either open a new terminal afterwards or send it to background via `nohup`.

Use the following command to inspect the status of Waydroid:

$ waydroid status
Session:        RUNNING
Container:      RUNNING
Vendor type:    MAINLINE
Session user:   user(10000)
Wayland display:        wayland-0

You can run the Android container in fullscreen (note that this isn't necessary to run apps):

$ waydroid show-full-ui

Run apps from the command-line:

$ waydroid app list
$ waydroid app launch com.android.settings

See waydroid -h for more information.

Autostart

By default, after installing Waydroid, the session will start automatically after starting a user session. This happens because the /etc/xdg/autostart/waydroid-session.desktop file is created after installation.

To disable autostart, create an overriding entry containing Hidden=true (source):

$ cp /etc/xdg/autostart/waydroid-session.desktop ~/.config/autostart/
$ nano ~/.config/autostart/waydroid-session.desktop
[Desktop Entry]
Hidden=true
# ...
# The rest of the lines in the file

GPS

Waydroid doesn't implement GPS passthrough by default, but the community has come up with various ways to fill this gap. Most of them are discussed in this issue in the Waydroid repo. For systems using geoclue, Geobridge is a mostly plug-and-play solution.

Troubleshooting

OSError: container failed to start

Several root causes can result in Waydroid failing to start with an OSError: container failed to start error.

The most common issue is that Wayland expects pulseaudio to be running and will fail with this obscure error message if it is not.

Work around this by creating an empty placeholder for the socket:

mkdir $XDG_RUNTIME_DIR/pulse/
ln -s $XDG_RUNTIME_DIR/pulse/native

See the upstream issue for further details.

Service manager /dev/binder has died

waydroid session start can fail with the following error:

[gbinder] WARNING: Service manager /dev/binder has died

This error is not written to the logs and only to stdout; keep an eye on the output of the command and not just the logs.

Work around this issue by adding psi=1 to the kernel's command line.

See the upstream issue for more details.

Networking

The container may not have access to the Internet out of the box. To access the network you need to allow access from and to the container via the firewall (otherwise DHCP will be blocked and the container will never get the IP) and configure a default gateway in the waydroid container (gateway IP is what your host device has on waydroid0 interface):

$ echo "ip route add default via 192.168.250.1" | sudo waydroid shell

If this fails with an error about an unreachable network, run:

$ sudo apk add waydroid-nftables

if you also see this error

RuntimeError: Command failed: % /usr/lib/waydroid/data/scripts/``waydroid-net.sh start
Warning: Extension udp revision 0 not supported, missing kernel module?

You need to install

$ sudo apk add iptables-legacy

Waydroid service not starting

Waydroid may take 15 - 20 minutes, with errors in logs during its initial boot. See https://forum.pine64.org/showthread.php?tid=15813 for more details.

Currently the Phosh build is using PulseAudio which will automatically suspend by default. This can prevent WayDroid from starting up or even randomly crash until PulseAudio is woken up again. If you are running into this, try playing some audio to keep Pulse awake (volume up/down every ~30 seconds works). Note that if your WayDroid service has been crashing, it may take 1-2 minutes to start up after waking Pulse. If you have confirmed that Pulse's suspend is causing issues, you can disable it by commenting out "load-module module-suspend-on-idle" (line 111) in /etc/pulse/default.pa. A reboot is recommended after updating the config.

Starting the Waydroid service

If you see something like this in your log:

(004537) [17:13:07] % sudo mount /usr/share/waydroid-extra/images/system.img /var/lib/waydroid/rootfs
mount: /var/lib/waydroid/rootfs: mount failed: Operation not permitted.

You most likely don't have the loop kernel module loaded or enabled. Try modprobe loop. If that doesn't work, make sure CONFIG_BLK_DEV_LOOP is enabled in your kernel.


Waydroid isn't launching

If your device uses Pulseaudio (I.E: You're on GNOME, Phosh or any GNOME fork), you're advised to:

$ nano /etc/pulse/default.pa   # [You can use any other text editor if you'd like]

Then go to line 111 and comment the following line:

load-module module-suspend-on-idle

↓ Becomes

#load-module module-suspend-on-idle

After this, you can restart your device (or Pulseaudio) and Waydroid should now "work". You'd have to nudge it by either connecting to a bluetooth speaker (or a computer running linux through bluetooth, they can act as speakers) or by playing audio, be it just making GNOME do the pop sound (volume rocker) or by playing something.

On GNOME mobile (not Phosh), as of March 30 on pmOS edge, doesn't seem to need the nudging previously mentioned.

RuntimeError Command failed

When you have issues similar to:

RuntimeError: Command failed: % mv /var/lib/waydroid/config_session /var/lib/waydroid/lxc/waydroid

the mentioned directory may not exist. Don't create it manualy, but run:

waydroid upgrade

Related

See also