Waydroid: Difference between revisions

Add suggestions about running arm in x86_64 from the web to the document
Onny (talk | contribs)
V4L2 camera forwarding: Simplify setup instructions
 
(33 intermediate revisions by 12 users not shown)
Line 1: Line 1:
[https://waydro.id Waydroid] is an application which uses LXC containers to run Android applications on a non-Android system.  
[https://waydro.id Waydroid] is an application which uses LXC containers to run Android applications on a non-Android system.  


{{Warning|Waydroid requires a Wayland desktop session and cannot be used on X11 directly, but can be run in a nested Wayland session, using e.g. [https://www.hjdskes.nl/projects/cage cage].}}
{{Warning|Waydroid requires a [[Wayland]] desktop session and cannot be used on X11 directly, but can be run in a nested [[Wayland]] session, using e.g. [https://www.hjdskes.nl/projects/cage cage].}}
{{Warning|Installing Waydroid on your system before running nixos-generate-config will create unnecessary fstab entries that may interfere with system functionality.}}


== Installation ==
== Installation ==
{{Warning|Installing Waydroid on your system before running nixos-generate-config will create unnecessary fstab entries that may interfere with system functionality.}}


Enable Waydroid in your system configuration:
Enable Waydroid in your system configuration:
Line 11: Line 12:
{
{
   virtualisation.waydroid.enable = true;
   virtualisation.waydroid.enable = true;
  # Newer kernel versions may need
  virtualisation.waydroid.package = pkgs.waydroid-nftables;
  # Enable clipboard sharing
  environment.systemPackages = [ pkgs.wl-clipboard ];
}
}
</nowiki>}}
</nowiki>|name=|lang=}}




Line 22: Line 28:
$ sudo waydroid init
$ sudo waydroid init
</syntaxhighlight>
</syntaxhighlight>
How to certify a waydroid device for GAPPS[https://github.com/waydroid/waydroid/issues/379#issuecomment-1152526650]


Before the following steps, you might need to do some GPU adjustments. See the troubleshooting section.
Before the following steps, you might need to do some GPU adjustments. See the troubleshooting section.
Line 27: Line 35:
== Usage ==
== Usage ==


Start the container
Start the container and userspace Wayland session. You'll know it is finished when you see the message "Android with user 0 is ready".


<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
Start the Waydroid LXC container
$ sudo systemctl start waydroid-container
$ sudo systemctl start waydroid-container
You'll know it worked by checking the journal You should see "Started Waydroid Container".
$ sudo journalctl -u waydroid-container
Start Waydroid session
You'll know it is finished when you see the message "Android with user 0 is ready".
$ waydroid session start
$ waydroid session start
</syntaxhighlight>
</syntaxhighlight>
Line 62: Line 63:
$ waydroid prop set persist.waydroid.width 608
$ waydroid prop set persist.waydroid.width 608
</syntaxhighlight>
</syntaxhighlight>
== Customization  ==
=== Running applications that differ from the current host architecture via libhoudini<ref>Need help with activating libhoudini for waydroid on NixOS
https://www.reddit.com/r/NixOS/comments/15k2jxc/need_help_with_activating_libhoudini_for_waydroid/</ref> ===
# Add NUR to your flake or shell or something like that base on [https://github.com/nix-community/NUR readme]
# Add nur.repos.ataraxiasjel.waydroid-script to your packages, if you were using nixos then set it as a item in environment.systemPackages, HM then home.packages.
# Use  `sudo waydroid-script` to run the script
# Select Android 11 >> Install >>  libhoudini, which the script only support libhoudini in this version.


== Maintenance  ==
== Maintenance  ==
Line 94: Line 84:


Removing images and user data
Removing images and user data
$sudo rm -r /var/lib/waydroid/* ~/.local/share/waydroid
$ sudo rm -r /var/lib/waydroid/* ~/.local/share/waydroid
</syntaxhighlight>
</syntaxhighlight>


== Troubleshooting ==
== Tips and tricks ==
 
=== Mount host directories ===
 
Install and configure graphical application <code>waydroid-helper</code><syntaxhighlight lang="nix">
environment.systemPackages =  [ pkgs.waydroid-helper ];
 
systemd = {
  packages = [ pkgs.waydroid-helper ];
  services.waydroid-mount.wantedBy = [ "multi-user.target" ];
};
 
</syntaxhighlight>Enable the user service which is also required. Note that this is not persistent and needs to get started after reboot again.<syntaxhighlight lang="bash">
systemctl --user start waydroid-monitor
</syntaxhighlight>Now start <code>waydroid-helper</code> application and add a shared directory. As an example, source directory could be <code>/home/myuser/Public</code> and target directory <code>/home/myuser/.local/share/waydroid/data/media/0/NixOS</code>. Ensure that both directories already exist locally. After that you might need to restart the ''Waydroid'' container which is also possible with the graphical user interface.
 
=== GPS/Location forwarding ===


=== GPU Adjustments ===
First enable ''geoclue2'' and ''adb'' daemon on the host<syntaxhighlight lang="nix">
services.geoclue2.enable = true;
programs.adb.enable = true;
</syntaxhighlight>Enable location provider in your desktop environment. For Gnome Shell you can do this<syntaxhighlight lang="bash">
gsettings set org.gnome.system.location enabled true
</syntaxhighlight>To test and see location<syntaxhighlight lang="bash">
nix shell nixpkgs#geoclue2 -c $(nix eval --raw nixpkgs#geoclue2)/libexec/geoclue-2.0/demos/where-am-i
</syntaxhighlight>Get IP address of the Waydroid guest and connect ''adb'' to it<syntaxhighlight lang="bash">
waydroid shell ip addr show
adb connect <IP>:5555
</syntaxhighlight>Download, initialize and run geobridge script<syntaxhighlight lang="bash">
wget https://gitlab.com/papiris/geobridge/-/raw/main/geobridge.sh
sh geobridge.sh --init
</syntaxhighlight>


In case you have an NVIDIA card or an RX 6800 series, you'll need to disable GBM and mesa-drivers:
=== V4L2 camera forwarding ===
{{file|/var/lib/waydroid/waydroid_base.prop|prop|<nowiki>
ro.hardware.gralloc=default
ro.hardware.egl=swiftshader
</nowiki>}}


=== Linux 5.18+ ===
Camera forwarding using V4L2 is broken on upstream, but can be achieved by using the Waydroid images of the [https://github.com/WayDroid-ATV Waydroid-ATV project]. You might [[Waydroid#Resetting Android Container|need to reset]] your existing Waydroid environment. Then stop the container and fetch the latest Waydroid-ATV images.<syntaxhighlight lang="bash">
systemctl stop waydroid-container
waydroid init -f \
  -c https://waydroid-atv.github.io/ota/a16-qpr2/system \
  -v https://waydroid-atv.github.io/ota/a16-qpr2/vendor \
  -r lineage \
  -s GAPPS
systemctl start waydroid-container
waydroid session start


Linux 5.18 and later removed ashmem in favor of memfd, so you may need to tell Waydroid (1.2.1 and later) to use the new module:
</syntaxhighlight>In case the graphical interface wont show up or the setup wizard fails you can do<syntaxhighlight lang="bash">
{{file|/var/lib/waydroid/waydroid_base.prop|prop|<nowiki>
waydroid shell -- am start -a android.intent.action.MAIN -c android.intent.category.HOME 
sys.use_memfd=true
waydroid shell -- pm disable-user --user 0 com.google.android.setupwizard
</nowiki>}}
waydroid shell -- pm disable-user --user 0 com.google.android.gms.setup
</syntaxhighlight>In case the camera access will crash the Waydroid container, there's a recent image which solves this on AMD GPUs. Download it and extract the contents to <code>/etc/waydroid-extra/images</code>. After that recreate the environment as mentioned above but only issue <code>waydroid init -f</code>.


=== Changing keyboard layout ===
=== Running applications that differ from the current host architecture via libhoudini or libndk<ref>Need help with activating libhoudini for waydroid on NixOS


According to [https://github.com/waydroid/waydroid/issues/209 an upstream issue], changing the keyboard layout doesn't seem possible at the moment.
https://www.reddit.com/r/NixOS/comments/15k2jxc/need_help_with_activating_libhoudini_for_waydroid/</ref> ===


=== Missing UTF-8 support ===
Run <code>nix shell github:nix-community/NUR#repos.ataraxiasjel.waydroid-script -c sudo waydroid-script</code>


According to [https://github.com/waydroid/waydroid/issues/536 an upstream issue], Android might fail to display special characters correctly.
Or, alternatively, add <code>nur.repos.ataraxiasjel.waydroid-script</code> from the NUR to your flake or shell or NixOS <code>environment.systemPackages</code>, or HM <code>home.packages</code> or something like that based on [https://github.com/nix-community/NUR readme] and run <code>sudo waydroid-script</code>


=== Waydroid interferes with suspend/hybernation ===
In the TUI, select Android 13 > Install > libhoudini (or libndk, [https://github.com/casualsnek/waydroid_script/blob/fcb15624db0811615ea9800837a836c4777674bf/README.md#install-libndk-arm-translation which script author claims may be faster on AMD])


According to [https://github.com/waydroid/waydroid/issues/168 an upstream issue], Waydroid might interfere with suspend or hybernation. You might have to stop the Android session and container to suspend your machine correctly.
== Troubleshooting ==


=== Clipboard sharing ===
=== GPU Adjustments ===


Add <code>wl-clipboard</code> to <code>environment.systemPackages</code>.
In case you have an NVIDIA card or an RX 6800 series, you'll need to disable GBM and mesa-drivers:
{{file|/var/lib/waydroid/waydroid_base.prop|prop|<nowiki>
ro.hardware.gralloc=default
ro.hardware.egl=swiftshader
</nowiki>}}


==See Also:==
==See Also:==


* [https://wiki.archlinux.org/title/Waydroid Waydroid article on the Archlinux Wiki]
* [https://wiki.archlinux.org/title/Waydroid Waydroid article on the Archlinux Wiki]