Follow to see more great articles like this~

Android apps on Linux with Waydroid

July 19, 2022
This article was contributed by Sam Sloniker
DeepL assisted translation
https://lwn.net/Articles/901459/

It's not uncommon for users to want to run a program for another operating system on one type of system. With the increasing popularity of smartphones, Android has become the most widely used operating system in the world. Therefore, users may want to run Android applications on Linux systems in order to obtain games or other applications that do not otherwise exist in Linux, or to develop mobile applications on their own Desktop systems. The Waydroid project provides a way to run these applications on Linux, which means they can run on a variety of devices, even Linux-based smartphones like the PinePhone.

Waydroid is similar in concept to Wine, the compatibility layer tool for Windows. The fact that Android runs on the Linux kernel makes it much simpler to run Android apps correctly on other Linux systems than on Windows. However, it is still not possible to simply run Android applications on a normal Linux operating system because they rely on different user-space environments. However, by using kernel features such as namespace, it is possible to run the entire Android user space in a container on a Linux system. That's the technology Waydroid uses; it runs a full Android system in a container the same way Debian runs in a container on Fedora. This allows Waydroid to perform better than running in a virtual machine or emulator.

picture

[Home screen on PinePhone]

Waydroid runs a customized version of the LineageOS Android distribution. It has all the software features of LineageOS, although it does not emulate all device features. For example, camera and phone functions are not supported; WiFi and Bluetooth also cannot be configured inside Waydroid. However, networks are still supported; Waydroid always appears to have an Ethernet connection, which is actually routing these network traffic through the host. Both audio input and output use the audio path configured by host. Aside from small differences like these, Waydroid is basically like a normal Android device without Google apps.

Hardware support

Waydroid supports 32-bit and 64-bit x86 and Arm. 64-bit Arm supports the most apps because it is the architecture used by the vast majority of regular Android devices, but many apps can also run on 64-bit x86. However, I have not tested 32-bit devices. Many applications are written entirely in Java and/or Kotlin, both of which can be compiled to architecture-independent Java Virtual Machine (JVM) bytecode; these applications can run on all architectures without requiring a developer Do any extra work. Other applications include native code compiled from languages ​​such as C or C++; these applications must be compiled separately for each platform, but many developers still compile for X86, since most Chromebooks (many of which are X86 processors) ) also supports Android applications.

GPUs from Intel and AMD, as well as those integrated in most Arm SoCs, support hardware graphics acceleration. NVIDIA GPUs are not yet supported (except those in Tegra Arm SoCs), but Waydroid does support the use of software rendering as a workaround.

I'm on my PinePhone (64-bit Arm, running DanctNIX and Phosh), two laptops (Dell Inspiron and Lenovo IdeaPad 3, both x86-64 and running Arch Linux) and my tablet (Microsoft Surface Go 2, also Waydroid was tested on x86-64 running Arch Linux; all devices have touchscreens. I use Wayland on all four devices because Waydroid depends on Wayland.

Unsurprisingly, the overall experience on the phone is the best. The experience of using Waydroid on a PinePhone is not much different from using a regular Android phone, except for the limitations of Waydroid that don't exist on regular Android devices, such as the phone and camera not working. Since the PinePhone's hardware is slower than most other Android devices, I disabled the UI animations. But it's a hardware problem, not a Waydroid problem. With animations disabled, the Waydroid is almost as responsive as a real Android phone.

picture

[2048 game on the notebook]

Waydroid also performs pretty well on laptops. Since most applications are not optimized for using a keyboard and mouse, I use my laptop's touchscreen more in Waydroid, which is not the same as using normal Linux software. Quite a few apps are designed to support keyboard and mouse input for compatibility with Chromebooks, so the effect experience of these apps is even better. The experience will be much worse on a desktop or non-touch laptop, but Chromebook-optimized apps will still work just fine.

On tablet tablets, touch gestures don't work properly (swipe actions are registered as a long press at a certain point), although they work fine on Linux itself; this makes Waydroid almost unusable on tablets. I didn't do a lot of testing due to this issue. However, Surface devices often have issues with Linux, so this is likely a problem specific to this device (maybe even my software configuration) rather than a general problem with Waydroid on tablets.

Waydroid does not work directly with the default kernel provided by some distributions because it requires the binder and ashmem modules. It appears that both Ubuntu and Debian provide these modules by default, while Fedora and Arch do not. I haven't checked other distros. On laptops and tablets, I installed linux-zen, an optional kernel available for Arch, which does provide these modules. DanctNIX's default kernel on the PinePhone provides these modules, so I don't need to replace its kernel.

The process of installing and running Waydroid varies on different distributions. I followed the instructions on the Arch wiki for my laptop, so after installing the Zen kernel, I installed waydroid and waydroid-image from the Arch User Repository (AUR). After that, Waydroid needs to be initialized with "sudo waydroid init" and the waydroid-container service needs to be enabled and started for systemd. There are instructions in the Waydroid documentation for installing it on other distributions.

Waydroid has two modes, multi-window mode and full UI mode. When using multi-window mode, Android apps are integrated into the desktop as if they were Linux desktop apps. However, on all four devices, the multi-window mode had several bugs that made it difficult to use, so I just used the full UI mode. That is, running the entire Android UI in the same window.

Waydroid creates .desktop files for every installed application, including default system applications, which cannot be disabled. These desktop files start the application in multi-window mode. However, if you only use the full UI mode, they just give you unnecessary misunderstandings in the menus. These icons can be hidden by adding Hidden=true at the end of each waydroid.*.desktop file in ~/.local/share/applications. Deleting the .desktop files is of no use, as Waydroid will create them again the next time it starts.

App support

As expected, app support on the PinePhone is the best since it's an Arm device and most Android apps are primarily designed for phones. On the laptop, most applications are available, although mouse support is incomplete for many; the touchscreen works fine.

picture

[F-Droid]

One of the most notable differences between Waydroid and a typical Android device is its lack of Google apps. This is certainly good for privacy, but it does have some drawbacks. Many apps won't install or work properly without Google Apps and Services.

The Google Play Store is unavailable, significantly limiting the number of apps that can be installed. Many apps that work well in Waydroid, especially proprietary apps, cannot be easily installed because they are only distributed through the Play Store.

F-Droid works well in Waydroid and does have good mouse support. The vast majority of applications listed without "anti-features" will work, and many will work with anti-features. The anti-feature most likely to cause problems is "non-free dependencies": usually, the non-free software that this anti-feature refers to is Google Play Services. This can lead to issues like no push notifications or missing maps or even the inability to open the app. Of course, apps that rely on unsupported hardware features won't work either, regardless of whether they have any anti-features.

It appears to be possible to get some of these apps working by installing microG, but I didn't test it out of concern that using it might violate Google Play's terms of service. Aurora Store is an alternative Play Store client that will likely work in Waydroid to install many Play Store-only apps; I haven't tested it for the same reason.

One limitation of Waydroid is that when a link is clicked in an Android app, there is no option to open the link in the host browser without installing additional software. In the Waydroid repository, there is an issue still open about this issue, but there is a workaround until this feature is implemented, I wrote a Python script and Android app to add this functionality. The Android application is installed in the Waydroid container and is set as the default browser (although it is not a real browser, it is configured to appear in the list of available browsers), while the Python script runs on the host OS. When a link in an Android app is clicked, the "browser" communicates with the Python script, which then opens the real browser on the host.

Waydroid development work is carried out in the GitHub repository. The project's website lists three members of the development team, while GitHub currently shows 25 contributors in the main repository. The latest version, V1.2.1, was released in April, but there has been considerable development since then. In general, the timing of the release is somewhat arbitrary; the first version listed on GitHub, V1.1.0, was released in September 2021, with V1.1.1 two days later. The next version, v1.2.0, was released a month after that, and then there was no release between October and April.

Conclusion

Overall, despite some issues and drawbacks, Waydroid is an effective way to run Android applications on Linux, especially on non-Android Linux phones. Like any software, it has some bugs, but most of its problems are caused by inherent differences between computers that run only or almost exclusively FOSS and smartphones that have a lot of proprietary software; on most Android devices Services considered essential are missing from Waydroid. And, when it's used on a desktop or laptop, the input devices (keyboard and mouse) are fundamentally different from the touchscreens that Android (and most of its apps) are primarily aimed at. The Android UI and many apps already have good keyboard and mouse support and are compatible with Chromebooks, but it's clear that Android was primarily designed for smartphones.

Unfortunately, devices without Google Play Services and the Play Store are so rare that developers have little incentive to avoid Play Services or distribute their apps on other channels; the main exceptions are FOSS and/or those privacy-conscious apps developer of . Of course, some Linux users wouldn't want to use these other non-FOSS apps anyway, so this might not be a problem for many Waydroid users.

Even with these limitations, Waydroid greatly expands the range of software available to Linux users, especially those with Linux smartphones. Of course, it's not an ideal solution, any more than Wine is an ideal solution to the lack of Linux desktop software; it would certainly be better if there were more native mobile-Linux applications. In general, however, Waydroid is quite useful for Linux phone users who don't want to be limited to a handful of native apps designed for Linux phones. Waydroid is definitely worth trying on any device looking to run Android apps.

Full text
LWN article is licensed under CC BY-SA 4.0.

Welcome to share, reprint and re-create based on the existing agreement~

Long press the QR code below to follow, follow LWN in-depth articles and various recent remarks from the open source community~

picture