In this tutorial we will be looking at how you can mirror your Android device. You might have been using Vysor but it is just ugly and lags. And also it costs for you to use it without ads. So here we will look how to install the alternative scrcpy to mirror your Android device.
To be honest I have never really used the Vysor. I have used ADB to wirelessly connect and controlled my device manually. But it’s really painful when you have to jump back and forth. It’s just so unproductive doing that. Let us see how scrcpy changes this for us.
Currently I have this article available for Ubuntu only. I will soon update it for windows users.
Why use scrcpy ?
Before diving right into the installation part let me provide you some insight on why you must use scrcpy.
Scrcpy is an application which mirrors your Android device via. ADB over wired or wireless connection. And the most important bit is that it doesn’t require any rooting.
It is free and open source. It is really light and doesn’t have much overhead. It’s response time is quick claims are 30 ms – 70 ms. And it doesn’t install any additional application in your Android device. It also launches quickly.
Besides performance and quality are top notch. There are no lagging issues whatsoever. And you can adjust the transmission rate to make it more smooth or good looking.
Now let us look at how to install it.
Android device must be at least Lollipop ( SDK 21 ) for this to work.
We can quickly get the package from the repository. But I have run into issues while doing so.
The ADB versions must match exactly or else you cannot push APKs from Android Studio. There will be endless kill server and start server where between two separate ADB versions. Which I have faced during my first encounter with scrcpy.
Let us just install scrcpy to avoid that by simply building it from source. The installation part is below but you must follow along to install it.
So what then ? Let us compile from the source. Don’t worry I will guide you.
Setting up prerequisites
We have to get a bunch of dependencies before we can start with the compilation.
Run the following commands to get the runtime dependencies.
sudo apt install ffmpeg libsdl2-2.0-0
If you have already got the dependencies you will get something like below.
Also Read : Learn to Implement Run Length Encoding in JavaTECHENUM
Making ADB available
Assuming you are an Android developer. Because as a normal user these steps are unnecessary. You can follow here to just set it up for normal use.
Also assuming the default method did not work because of conflicting ADB versions. Because you have the latest ADB installed because of Android Studio. This might cause issue sometimes hence we are building the app from source.
If you don’t see something like below when you type
adb in your terminal. You must export
adb path. Let us just do that and update
platform-tools directory path. And add it to end of the file
You obviously have to replace the path with your own path.
Once that’s done do
source ~/.bashrc to refresh the variables for current bash session. You must do this every time you update something in
For client build
We must also get compile time dependencies before we can continue.
sudo apt install gcc git pkg-config meson ninja-build \ libavcodec-dev libavformat-dev libavutil-dev \ libsdl2-dev -y
Everything should complete without any errors.
Let us move on to installing dependencies further.
For server build
If you develop Android applications. You might already have Java installed on your system.
To check if java is installed type the following command.
Before you install Java know that there is already a
JDK included in the
jre directory of your Android Studio installation. You can just export it like we have in the
But if you want to install Java separately run the following command.
sudo apt install openjdk-8-jdk
Also Read : Consume an API with Retrofit in AndroidTECHENUM
According to the docs it states that if you have Ubuntu prior 16.04 this will cause issue. But I was facing this issue even with 20.04. Let’s update meson.
pip3 if already installed it doesn’t matter.
sudo apt install python3-pip -y
Now install meson with the
pip3. You can find the latest meson version from here. During writing this article it is
0.55.3 so I will be using that.
pip3 install 'meson==0.55.3'
You will see something like below. If you don’t have the expected version do export the path.
Also Read : 5 Productivity Tips and Tricks for UbuntuTECHENUM
Setting up ANDROID_SDK_ROOT variable
Let us once again edit the
~/.bashrc to export the
That’s pretty much it let’s get on with actually compiling from source.
Building and Installing scrcpy
Now that we have already installed our dependencies. We have only one more thing left to do. And that is building the program itself from the code.
Also Read : How to get current GPS location in AndroidTECHENUM
Cloning the project
Run the command below to clone the project in your
git clone https://github.com/Genymobile/scrcpy ~/scrcpy
cd into the directory with
Then finally run the command below to start compiling from the source.
Setting up build
meson x --buildtype release --strip -Db_lto=true
You will see something like below
Finally run the command
It will take some time because it will download and setup the gradle files for building. The time will depend on your internet speed.
The only error you might run into is
ANDROID_SDK_ROOT not defined. And if you do just check if you have configured it correctly in the above steps.
Upon success you will see something in your console like below
Installing the build
And that we have successfully build our program. Let us install it using the command below.
sudo ninja -Cx install
We will see the screen below after successful installation.
To check if the installation was successful run the command below. As there is an error but we have installed scrcpy successfully.
Everything has been done. Connect your device to the laptop with wire or via adb tcp/ip.
Make sure the device is recognized by ADB.
Now if you run
scrcpy you should see something like below.
Verifying our build
And the device screen should popup on your desktop like below.
We have successfully setup scrcpy in our Ubuntu machine. And now you have completed scrcpy install to mirror your Android device in your Ubuntu.
But wait there’s more to it than just that. If we close the terminal our scrcpy window will close too. Let us solve this.
Add the lines below to the
~/.bash_aliases file. If there is no file create one yourself with
Paste the code below in the file I just mentioned.
alias sconnect="scrcpy --always-on-top & disown"
What the code above does is that it starts the instance and immediately detaches from the terminal window. That way it will keep running even when the terminal windows is closed.
Did you run into any issues while performing scrcpy install to mirror your Android device ? Comment below if you face any issues.
Now using Ubuntu ? Follow the guide here.
Keep learning and keep growing.
Also Read : Learn how to use shared preferences in AndroidTECHENUM