A few days ago, I was suffering while trying to develop new features for a react-native app due to my machine not being powerful enough. I was aware of the minimum requirements to run the android emulator, would be this the only option, though?
TL;DR;
We can use scrcpy on machines where an android emulator is not an option, this way we can use our cellphone as an “emulator” and control or interact with it on the machine.
Running on android devices
What about using our device to run? This is not something new and is one of the potential solutions to solve our first problem. By the way, you can find it on react-native docs.
But you will want to interact with your application, and holding the cellphone is an awful developer experience. Moreover, what if you need to present the features you’ve done in a meeting with your client? That’s where scrcpy comes in!
What is scrcpy?
This application provides display and control of Android devices connected via USB or over TCP/IP. It does not require any root access. It works on GNU/Linux, Windows, and macOS.
The description we found on their GitHub repo is very self-explanatory. Scrcpy is an open-source library that helps us to control android devices via USB. When we say control, it’s not just about transferring files or basic stuff we usually do, we’re talking about full interaction with the device. Really cool, ain’t it? This solves the issues we just mentioned because we can have the android device on the monitor.
How to set up it
No, not like that!! Jokes (or not) aside, we will mirror the cellphone screen to the monitor using GitHub – Genymobile/scrcpy: Display and control your Android device but for that, we need to do some things first.
Enabling USB Debugging on Mobile
USB debugging is used by developers on Android devices to better communicate with computers, making application development more efficient. Naturally, it only works if the user has enabled developer mode on their smartphone, which allows access to different areas.
Ariane Velasco – CanalTech
To enable it, you can either read the official documentation or use this guide. As a short summary, this is what you need to do (be aware that names may vary depending on the device):
1 – Open Android Settings
2 – Go to About Phone
3 – Look for your Android version
number and click repeatedly until the development settings are activated
4 – After that, look in your settings for the Developer Options
5 – Enable USB Debugging
(keep in mind that some phones may also need to enable USB debugging (Security settings)
to be able to use a keyboard and mouse).
6 – Some phones may prompt a warning about what USB debugging
may do when active. If you are okay with all this, we can go ahead.
Installing scrcpy
In this guide, I will show you how to install scrcpy on Ubuntu, but if you want to see other ways or another operating system, you can take a look at the complete scrcpy documentation.
For Linux (Ubuntu/Debian), just run this command in your terminal:
apt install scrcpy
Yes, that’s all 🙃
Using scrcpy
After the enormous difficulty of installing scrcpy, let’s see how we can use it.
First, you need to connect your cellphone to the computer. Then thereafter, let’s open the terminal and run:
scrcpy
It’s expected to return an error, something like this:
Don’t worry, this error is part of the process. After reading the message, we see that it was generated because the device was not authorized. To resolve this, simply go to your cellphone and authorize the machine you’re using to access the device. Click ‘Always allow from this computer’ to avoid having to authorize the same machine each time you use USB debugging.
Subsequently, run the command again in your terminal:
scrcpy
If everything went well, your phone should now be mirrored on your PC.
Now, just run the project on your cellphone and use the scrcpy window.
Additional Information
There are several features for scrcpy, from bidirectional copy & paste to even recording screen videos. You can see all of them here. However, I’ll give you some configurations I use the most.
Stay awake – To prevent the device from locking the screen:
scrcpy --stay-awake
scrcpy -w
Turn screen off – To turn off the cellphone screen, but keep awake on the monitor:
scrcpy --turn-screen-off
scrcpy -S
Looking like this to start scrcpy:
scrcpy -w -S
⚠️ Notifications
It deserves to be highlighted. Definitely, you would rather not share particular messages while sharing your screen, right? So make sure you disable notifications since this is your phone.
Conclusion
Scrcpy can be a wonderful tool for developers, it can help you with screen recordings and screenshots. It also can work as an emulator for testing your software because this is not only a screen mirroring, but enable mouse and keyboard and even copy & paste between your cellphone and the computer. It can be used in many ways, not only for those who need an emulator, but for those that want to have access to some tools without needing to set up an entire emulator for it.
We want to work with you. Check out our "What We Do" section!