Waydroid - Run Android Apps On Linux


How to Run Android Apps on Linux Using Waydroid

Want to run your favorite Android apps directly on your Linux desktop? In this guide, I'll walk you through setting up Waydroid, a container-based solution that lets you run a full Android system on Linux. Whether you're using Xorg or Wayland, this tutorial will get you up and running with apps like Instagram, TikTok, and more.

 What is Waydroid?

Waydroid is a Linux program that functions like a container with a complete Android system inside. Think of it as Docker, but with a full-blown Android installation. It offers near-native performance, app integration, and it's completely free and open-source.



 What You'll Be Able to Do

Once set up, you'll have:

- A phone-shaped Android window on your desktop
- Access to the full Android interface, including the app menu
- The ability to install and run Android apps
- Features like force-stopping apps and using the file manager
- Internet connectivity for your Android apps


 Prerequisites

This guide focuses on systems using Xorg display server (like Linux Mint or Ubuntu). If you're using Wayland, the process is simpler with fewer steps.



Installation Steps

Step 1: Install Waydroid

First, visit the Waydroid website and navigate to the installation documentation. Find your Linux distribution in the list. For Ubuntu-based systems (including Linux Mint):

```bash


Update your system


sudo apt update



Install prerequisites

sudo apt install curl ca-certificates



Download the installation script


cd ~/Downloads
curl -O https://repo.waydro.id/install.sh


Review the script (always do this!)


cat install.sh



Run the installation script

sudo bash install.sh



Install Waydroid


sudo apt install waydroid
```

 Step 2: Download the Android System Image

After installing Waydroid, you need to download the Android system image:

```bash
waydroid init
```

This will download a vanilla Android image, which can be several gigabytes. Wait for the process to complete until you see "Done."

Step 3: Configure for Virtual Machines or NVIDIA GPUs (Optional)

If you're using a Virtual Machine or have an NVIDIA GPU and encounter issues, you'll need to modify a configuration file:

```bash
sudo xed /var/lib/waydroid/waydroid.cfg
```

Add these two lines under the

 `[properties]` tag:
```
ro.hardware.gralloc=default
ro.hardware.egl=swiftshader
```

Then apply the changes:


```bash
sudo waydroid upgrade
```



Step 4: Install Weston (For Xorg Users Only)

Since Waydroid is designed for Wayland and you're on Xorg, you need to install Weston, a Wayland compositor that runs in a window:

```bash
sudo apt install weston
```

If you're already using Wayland, skip this step.



 Step 5: Configure Firewall Rules

To enable internet connectivity in Waydroid, you need to adjust your firewall settings. Run these three commands (note: this changes your security settings):

```bash
sudo iptables -A FORWARD -i waydroid0 -j ACCEPT
sudo iptables -A FORWARD -o waydroid0 -j ACCEPT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
```


 Step 6: Set Up Environment Variables

To prevent new windows from opening inside Weston, configure these environment variables:

```bash
export WAYLAND_DISPLAY=mysocket
weston --socket=mysocket --backend=x11-backend.so --width=486 --height=1000 &
```

The width and height parameters create a phone-shaped window. Adjust these values to your preference.


 Step 7: Enable ARM App Support

Most Android apps are built for ARM processors. To run them on your x86-64 system, you need the Waydroid Script tool:

```bash
# Install dependencies
sudo apt install git python3-venv

# Clone the repository
cd ~/Downloads
git clone https://github.com/casualsnek/waydroid_script
cd waydroid_script

# Set up Python virtual environment
python3 -m venv venv
source venv/bin/activate

# Install requirements
pip install -r requirements.txt

# Run Waydroid Script
sudo python3 main.py
```

In the Waydroid Script interface:


1. Select "Install"
2. Choose your Android version (check this in Settings > About)
3. Select the packages you want:
   - **MicroG**: Minimal Google services for most apps
   - **libndk** (AMD CPUs) or **libhoudini** (Intel CPUs): ARM translation layer
4. Choose "standard" installation
5. Wait for the download and installation to complete



 Installing Apps

Method 1: F-Droid (Open-Source Apps)

After running Waydroid Script, you'll have F-Droid installed, an app store for open-source Android apps. Open it, accept the terms, and browse available apps.


Method 2: Aurora Store

Aurora Store is an open-source alternative that provides access to official Android apps from the Play Store. Install it through F-Droid.

 Method 3: Sideloading APK Files

If you have APK files, you can install them directly:

```bash
cd ~/Downloads
waydroid app install app-name.apk
```

 Creating a Startup Script

To avoid typing commands every time, create a simple script:

```bash
# Create the script file
sudo touch /usr/local/bin/startandroid

Edit the script

sudo xed /usr/local/bin/startandroid
```

Add this content:


```bash
#!/bin/bash
export WAYLAND_DISPLAY=mysocket
weston --socket=mysocket --backend=x11-backend.so --width=486 --height=1000 &
waydroid show-full-ui &
```

Set permissions:


```bash
sudo chmod 755 /usr/local/bin/startandroid
sudo chown 0:0 /usr/local/bin/startandroid
```

Now you can start Android with just one command:


```bash
startandroid
```

Important: Stopping Waydroid

Every time you close Waydroid, it continues running in the background. Always stop it properly:

```bash
waydroid session stop
```

Troubleshooting Tips

- **No internet connection**: Check your firewall rules

- **Apps won't run**: Make sure you installed the ARM translation layer (libndk or libhoudini)

- **Aurora Store crashes**: Try sideloading APK files instead

- **Windows opening in Weston**: Verify your environment variables are set correctly

Conclusion

You now have a fully functional Android environment running on your Linux machine! You can install apps, browse the web, and use your favorite Android applications right from your desktop. The setup process might seem involved, but once it's configured, running Android apps is as simple as executing a single command.

Happy tinkering, and enjoy your Android apps on Linux!





Comments

Popular posts from this blog

Building AI Ready Codebase Indexing With CocoIndex

Code Rabbit VS Code Extension: Real-Time Code Review