DEV Community

Cover image for Mirror Android device on desktop screen with scrcpy
Sven Schwyn
Sven Schwyn

Posted on • Updated on

Mirror Android device on desktop screen with scrcpy

A growing number of services such as online banking are accessible on mobile devices only these days, so you may find yourself typing IBANs or reference numbers on tiny on-screen keyboards while your desktop computer keyboard sits right next to it laughing at you.

Stop this, let's mirror the Android device on the desktop screen!

There are quite a few commercial remote control solutions out there, some of which offer limited free tiers once you've registered online. However, particularly when it comes to remote access, I prefer open-source tools which don't require any third party server.

Enter scrcpy, a lightweight CLI tool available for macOS, Linux and Windows. It communicates via ADB which is preinstalled on every Android device and doesn't require it to be rooted.

Prep the Android device

On the Android device, open developer options and enable «Android debugging (ADB)». (In case you don't find the developer options, you have to enable those beforehand.)

ADB requires a USB connection by default which is secure, but not very handy. If and only if you are on a secure private network, you may use a TCP/IP connection instead, say your home wifi network. Check available widgets, you might find one called «ADB over network» to easily switch this feature on and off.

Just to make sure you've understood the risks: Never enable «ADB over network» on insecure public networks!

Install scrcpy on the desktop computer

The following is for Macs, but you find instructions for Linux or Windows on the scrcpy README.

Unless already present, install Homebrew on your Mac. Then open a terminal and install scrcpy as well as the offical Android development tools.

brew install scrcpy
brew install android-platform-tools
Enter fullscreen mode Exit fullscreen mode

You might also want to set an aliases in order not having to memorize scrcpy and it's options. Here's the alias when using a USB connection:

# macOS 12 or newer
echo 'alias android="scrcpy --stay-awake"' >>~/.zshrc
source ~/.zshrc

# macOS 11 or older
echo 'alias android="scrcpy --stay-awake"' >>~/.bash_profile
source ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

When using a TCP/IP connection, you have to make sure your Android device always gets the same IP address assigned by the router. The following assumes the device on IP 192.168.1.10:

# macOS 12 or newer
echo 'alias android="scrcpy --tcpip=192.168.1.10 --bit-rate 2M --max-size 800 --stay-awake"' >>~/.zshrc
source ~/.zshrc

# macOS 11 or older
echo 'alias android="scrcpy --tcpip=192.168.1.10 --bit-rate 2M --max-size 800 --stay-awake"' >>~/.bash_profile
source ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Spieglein, Spieglein

Time to mirror! Either connect the Android device to the computer or enable «ADB over network», then open a terminal on the Mac and type:

android
Enter fullscreen mode Exit fullscreen mode

A window should pop up and mirror the Android screen. You can mouse around, type input, even copy/paste as if it were just another application running. 🎉

Given the multitude of different Android devices, this might not work at the first attempt. You find troubleshooting hints in the scrcpy README.

(Photo by Rishabh Dharmani on Unsplash)

Top comments (0)