Archives For Android

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

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.