Archives For November 30, 1999

 

This is beginner’s guide shows how to install and setup Waydroid to run full Android system as well as Android applications in Ubuntu.

I’ve written about this by using Anbox, which is however no longer in active development.

This is a re-write with free and open-source ‘Waydroid’, which is a container-based approach to run a minimal customized Android system image based on LineageOS.

Android OS in my Ubuntu 22.04 desktop

This tutorial is tested and works on Ubuntu 22.04, though Ubuntu 20.04, Ubuntu 23.10 are also supported! Hardware specs include:

  • CPU: Intel i5-10400.
  • GPU: Intel HD 630.

Step 1: Install Waydroid

Waydroid is easy to install in Ubuntu/Debian based systems, through its official apt repository.

1. First, press Ctrl+Alt+T on keyboard to open terminal. When it opens, run command to install required packages:

sudo apt install curl ca-certificates

sudo command needs password authentication, but with no asterisk feedback. Just type in mind and hit Enter.

2. Then, run command to download the official script, and run it to add Waydroid repository into your system.

curl https://repo.waydro.id | sudo bash

In case the script does not work properly, find out your OS code manually via either lsb_release -sc or cat /etc/os-release command. Then, run command below instead:

curl https://repo.waydro.id | sudo bash -s jammy

Replace jammy depends on your system code-name. So far, it supports focal, jammy, lunar, mantic, bookworm, bullseye, sid

3. Finally, run command to install Waydroid:

sudo apt install waydroid

Try sudo apt update first to refresh cache if the command output package not found

Once successfully installed the app, you should be able to launch it from start menu, applications menu, or any other app launcher depends on your desktop environment.

Step 2: Initialize

The first launch of the app, will launch the “Initialize Waydroid” dialog.

The default options are usually OK. But, you may have to choose Android type before getting start:

  • VANILLA – as name indicates, it’s vanilla ROM, without Google Services/Apps.
  • GAPPS – come with Google Services/Gapps.

Next, click Download button will automatically download & install ROM and required packages. In my case, it downloaded & installed Android 11.

When done successfully, it will show you something like the screenshot shows you.

Step 3: Start Android system, resize & move window

After clicking “Done” button in last step, start Waydroid again will launch an Android screen on your desktop.

However, it by default starts in full-screen (or may-be called maximized) mode.

To change the Android screen size, open terminal (Ctrl+Alt+T) in the Ubuntu host, and run commands:

waydroid prop set persist.waydroid.width 506
waydroid prop set persist.waydroid.height 1000

The 2 commands will set the screen width and height to 506 x 1000. Change the numbers accordingly, and apply by running command to stop current Android session (then re-launch).

waydroid session stop

The Android window is borderless in my case. To move the window, you may either press & hold Super (Windows logo) key then dragging, or press Alt+F7 and then move mouse cursor without mouse clicking.

Step 4: Install & Remove Android Apps

If you selected ‘VANILLA’ while initializing Waydroid, then there’s no app store in the Android to install applications.

In the case, you may download any APK file from the web, or download & install the free open-source F-Droid in the host (Ubuntu in the case) then use it in Android screen to install apps.

To install APK file from host user’s ‘Downloads’ folder, just run command in terminal (Ctrl+Alt+T):

waydroid app install ~/Downloads/file_name_here.apk

And, verify by listing all installed Android apps:

waydroid app list

Waydroid will create app shortcuts for all installed Android apps, through .desktop files under “.local/share/applications”. Meaning, you can search & launch Android apps directly from host machine (Ubuntu).

Launch ‘F-Droid’ Android app in Ubuntu

And, it supports launching multiple instance of Android apps at the same time out-of-the-box.

To remove an app, either do it in the Android screen, or run command in Ubuntu host:

waydroid app remove packageName

Replace packageName according to waydroid app list output, e.g., org.fdroid.fdroid.

Step 5: Share files between Ubuntu Host and Android

To share files between host and the Android system, simply run single command in Ubuntu host:

sudo mount --bind ~/Documents/vboxshare/ ~/.local/share/waydroid/data/media/0/Documents/share

In the command, you need to replace:

  • ~/Documents/vboxshare/ – ‘vboxshare’ sub-folder in Ubuntu host.
  • ~/.local/share/waydroid/data/media/0/Documents/share – ‘share’ sub-folder of Documents in Android.

You need to first create the share folder if not exist, or it will show mount point does not exist as the screenshot below shows you.

Uninstall Waydroid:

First, stop the session and container, which maybe useful for reloading settings, run commands:

waydroid session stop
sudo waydroid container stop

To remove Waydroid, use command:

sudo apt remove --autoremove waydroid

Then, remove leftovers by running command:

sudo rm -rf /var/lib/waydroid ~/waydroid ~/.share/waydroid ~/.local/share/applications/*aydroid* ~/.local/share/waydroid

If you don’t want to install it back any more, then, also remove the source repository by deleting the sources & key files:

sudo rm /etc/apt/sources.list.d/waydroid.list /usr/share/keyrings/waydroid.gpg

For more about Waydroid, see the official document.

The free open-source Android screen mirroring and remote control application, Scrcpy, released version 2.0 today!

The new release feature audio forwarding support! Meaning it’s not only mirroring your Android screen, but also sending the sound from Android to your PC speaker. The new feature supports Android 11 and higher. It’s enabled by default, though there’s --no-audio flag available to disable it.

Another big change in the release is that the device screen can now be encoded in H.265, or even AV1 if your device supports AV1 encoding.

The release also includes new --list-encoders option to list audio and video encoders available in the device, and --list-displays to list displays available on the device. For more about Scrcpy 2.0, see the official release note.

How to Install & Use Scrcpy in Ubuntu 22.04 to control your Android Phone Wirelessly or via USB cable

NOTE: This tutorial is tested and works in Ubuntu 22.04, though it should also work in all current Ubuntu releases.

Step 1. Prepare your Android device

To use the software, you need to first enable USB Debugging Mode in Android.

1. First, go to Settings in Android. Navigate to “About Phone”, and tap on “Build Number” several times (usually 7 times). It should prompt you something like “You are now in Developer Mode“.

TIP: there’s NO security issue or performance loss with developer mode enabled.

2. Then navigate to “Developer Options” in Settings menu or ‘Additional Settings’ sub-menu, and turn on the option for “USB Debugging“.

Step 2. Install adb

adb (Android Debug Bridge) package is also required for this software. Just press Ctrl+Alt+T on keyboard to open terminal and run command to install it:

sudo apt install adb

Step 3. Install scrcpy

There are few ways to install scrcpy, choose either one that you prefer.

Option 1: .deb package from system repository

Scrcpy is available in Ubuntu system repository. It’s working good in my case, though a little bit old that lacks new features.

To install the package, open terminal (Ctrl+Alt+T) and run command:

sudo apt install scrcpy

Option 2: Snap package in Ubuntu Software

The snap package in Ubuntu Software can be the easiest way to install the app, though it runs in sandbox.

The snap package at the moment is the last 1.25 version, though it will automatically update to v2.0 once maintainer updated the package.

Scrcpy Snap in Ubuntu Software

Option 3: Install Scrcpy from the source

If you can’t wait to use the latest release, open terminal (Ctrl+Alt+T) and run the command below one by one to install it from source:

  • First, run command to install dependency libraries:
    sudo apt install ffmpeg libsdl2-2.0-0 adb wget gcc git pkg-config meson ninja-build libsdl2-dev libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev libswresample-dev libusb-1.0-0 libusb-1.0-0-dev
  • Then, clone the source code via command:
    git clone https://github.com/Genymobile/scrcpy
  • Finally, navigate to source folder and start the installer script:
    cd scrcpy && ./install_release.sh

    NOTE: After building process it may ask you to type user password for the permission to install files into system directories.

Step 4. Remote control your Android in Ubuntu

Now, connect your Android device into Ubuntu using USB cable. Then, click “Allow” in Android to confirm the “Allow USB Debugging” dialog.

1. First, open terminal (Ctrl+Alt+T) and start adb in your favorite mode:

  • To remote access via USB cable, run command:
    adb usb
  • To remote access using wireless network, run commands:
    adb tcpip 7676
    adb connect 192.168.0.150:7676

    Here, change port number 7676 and the Android’s IP address accordingly! When done successfully, you can then remove the USB cable.

2. If the previous step goes well without any error! You can now start scrcpy:

  • Run scrcpy command in terminal if you installed from system repository.
  • Launch it from start menu (or ‘Activities’ overview) if installed from source. For debugging purpose, use scrcpy(console).

That’s all. Your android screen should appear in the Ubuntu desktop after launching scrcpy. Enjoy!

Uninstall scrcpy

To remove the adb package, open terminal and run command:

sudo apt remove --autoremove adb

To remove Scrcpy installed as .deb package, use command:

sudo apt remove --autoremove scrcpy

For the snap package, just use Ubuntu Software again to remove it.

And, for the package installed from source, navigate to the source folder again in terminal window and run command to uninstall it:

sudo ninja -Cbuild-auto uninstall

 

 
ANBOX IS NO LONGER IN ACTIVE DEVELOPMENT! Try the popular Waydroid instead!

Want to run Android apps in Linux? Here’s how to do it using the Anbox container in Ubuntu 20.04 and Ubuntu 21.10.

Anbox, Anbox in a box, is a free and open-source software that runs the full Android system in a container, abstracts hardware access and integrates core system services into a GNU/Linux system.

There’s another solution “Waydroid” to do the similar things in Linux. It’s said to have better performance, though it requires Wayland session. For those stick to Xorg, here’s how to install and use Anbox.

Load Kernel modules:

Anbox requires ashmem_linux and binder_linux kernel modules.

1.) If you have the SecureBoot enabled (check via sudo mokutil --sb-state command), open terminal by pressing Ctrl+Alt+T on keyboard, and run command to sign the kernel module:

sudo kmodsign sha512 /var/lib/shim-signed/mok/MOK.priv /var/lib/shim-signed/mok/MOK.der /lib/modules/`uname -r`/kernel/drivers/staging/android/ashmem_linux.ko

2.) Next load the modules one by one via command:

sudo modprobe ashmem_linux
sudo modprobe binder_linux

3.) Finally verify the kernel modules via command:

lsmod | grep -e ashmem_linux -e binder_linux

Install Anbox:

The software is available to install via official Snap and classic DEB packages, though I recommend the snap package this time. Because, the DEB is not well supported. User needs to manually mount binder, download and load Android image, and troubleshoot other issues. And it ultimately failed to run in my case.

To install Anbox snap, press Ctrl+Alt+T to open terminal, and run command:

snap install anbox --beta --devmode

After installation, you may try to launch Anbox by searching it from activities overview screen. However, it does not launch in my case until installed the Google Play Store. If so, try running the command below in terminal to start it:

anbox launch --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity

Install Google Play Store:

Anbox has a few built-in applications except Google Play Store, because Google will only permit certified devices to ship with their applications. Thankfully, there’s an installer script to automatically install it for you.

1.) Firstly, open terminal and run command to install some required libraries:

sudo apt install wget curl lzip tar unzip squashfs-tools

2.) Next, download the script via wget command:

wget https://raw.githubusercontent.com/geeks-r-us/anbox-playstore-installer/master/install-playstore.sh

3.) Add executable permission:

chmod u+x install-playstore.sh

4.) And run the script will download the package and install Play Store:

./install-playstore.sh

Now, search for and open Anbox from activities overview screen. When it opens, go to settings and grant all permissions to Google Play Store, and finally open the Play Store to install Android apps.

How to Remove Anbox:

To remove the software, simply run command in terminal:

snap remove --purge anbox

You may also remove the “anbox” and “anbox-work” folders in user’s home directory.