localdesktop

Introduction: Local Desktop helps you run a desktop Linux environment on your Android device.
More: Author   ReportBugs   OfficialWebsite   
Tags:

Local Desktop helps you run a desktop Linux environment on your Android device.

Local Desktop is a Rust rewrite of the original Polar Bear project, which was written in Kotlin and C++. The aim of this rewrite is to make it more stable, portable, and able to do the development work on Android.

How it works

  1. An Arch Linux ARM64 filesystem is set up inside the app's internal storage.
  2. Proot mounts the filesystem and provides a chroot-like environment.
  3. A minimal built-in Wayland compositor runs in Android NDK.
  4. Rootful Xwayland & a desktop environment launches inside the chroot and renders back to the Android native activity.

POC Proof of Concept: A Pixel Tablet running the XFCE desktop environment inside a Proot-based ARM64 Linux. No configuration is required; just install and go.

Getting Started

How to build an APK

Termux

You can build the Local Desktop APK directly on your Android device. This is simple because no cross-compilation is needed. However, we only ship prebuilt libs for arm64, so this option only works on ARM64.

For Termux, there are two supported approaches:

  1. Simple build (no xbuild)

    Install Rust:

    pkg i rust
    

    Then run:

    cargo run
    

    This uses the built-in Rust APK builder and writes localdesktop.apk in the project root.

  2. xbuild-based build

    This matches the desktop cross-build pipeline more closely and is better for repeated APK builds:

    bash scripts/build-termux.sh
    

    This script installs the required Termux packages, bootstraps the patched xbuild toolchain, downloads the Android SDK build-tools, and writes the APK to target/x/release/android/localdesktop.apk.

For the simple cargo run flow, you can install the APK with termux-open localdesktop.apk, but in some cases you may need to mv localdesktop.apk ~/storage/downloads and install it from there. Make sure you have run termux-setup-storage before moving it outside Termux.

Linux/Mac/Windows

The above option is suitable for quick development on Android. However, if you need to build an AAB (for distribution to Google Play), debug with Visual Studio Code, or compile for unsupported targets (like x64 Android), then you need to cross-build it from your PC. Along with Rust, please make sure you have these components installed:

brew install llvm lld gradle@8

Then install our local version of xbuild:

cargo install --path patches/xbuild/xbuild --force
x build --release --platform android --arch arm64 --format apk

Alternatively, trigger the default build task by pressing Ctrl+Shift+B.

You can find the output APK in:

open target/x/release/android/localdesktop.apk

Docker

If you have issues setting up your local development environment as detailed above, you can make use of the included Dockerfile to build an APK on a single command. This will take a long time so it's not recommended if you can make use of any of the other methods

make build-docker

You can find the output APK in:

open target/x/release/android/localdesktop.apk

How to develop

Termux

We recommend the following setup, but feel free to use your own favorite tools for development:

pkg install helix helix-grammars rust-analyzer

A wonderful thing about developing directly on Android is that an agent like Codex on Termux can test the code for you by running unit tests, reading the output, understanding what went wrong, and trying again. In my experience, this is not possible when cross-developing on other operating systems, so you have to run the tests yourself.

Developing on Android

Linux/Mac/Windows

Recommended setup:

  • IDE: Visual Studio Code

  • Extensions:

  • Instructions:

    1. Open Visual Studio Code.
    2. Launch the [Android] Debug configuration from the debug panel. This will:
      • Build the Rust code into an APK.
      • Install the APK on a selectable device, and launch the app in debug mode.
      • Redirect stdout/stderr output to the terminal.

It is easy to debug

Tip: You can debug the app on either a physical device or a virtual device.

For more instructions on how to work on this project, please visit the Developer Manual.

Apps
About Me
GitHub: Trinea
Facebook: Dev Tools