Connecting your phone wirelessly with ADB and Scrcpy in Linux

Wireless connections can be a convenient way to control and develop mobile applications. If you're working with an Android device, you can use ADB and Scrcpy to connect your phone wirelessly to your Linux machine. In this blog post, we'll show you how to connect your phone wirelessly using ADB and Scrcpy on Linux.

Installing ADB

ADB is a command-line tool used for communicating with Android devices. It can be used for various purposes, such as installing apps, copying files, and debugging.

To install ADB on Linux, follow these steps:

  1. Open the terminal on your Linux machine.

  2. Install ADB by running the following command:

     sudo apt-get install android-tools-adb
    

    This will install ADB and its dependencies on your Linux machine.

Installing Scrcpy

Scrcpy is a free and open-source tool used for displaying and controlling Android devices from your Linux machine. It can be used for various purposes, such as recording screen videos, testing mobile applications, and controlling your device wirelessly.

To install Scrcpy on Linux, follow these steps:

  1. Open the terminal on your Linux machine.

  2. Add the official Scrcpy PPA to your system by running the following command:

     sudo add-apt-repository ppa:genymobile/scrcpy
    
  1. Update your package list by running the following command:

     sudo apt-get update
    
  1. Install Scrcpy by running the following command:

     sudo apt-get install scrcpy
    

This will install Scrcpy and its dependencies on your Linux machine.

Enabling developer options on your Android phone

Before you can connect your phone to your Linux machine using ADB, you need to enable developer options on your Android phone. To do this, follow these steps:

  1. Open the Settings app on your Android phone.

  2. Scroll down and select "About phone."

  3. Scroll down to the "Build number" option and tap it seven times. You will see a message that says "You are now a developer!"

  4. Go back to the main Settings screen and select "Developer options."

  5. Toggle the "Developer options" switch to the "On" position.

  6. Scroll down to the "Debugging" section and toggle the "USB debugging" switch to the "On" position.

Connecting your phone wirelessly

To connect your phone wirelessly using ADB and Scrcpy, follow these steps:

  1. Connect your phone via USB to your Linux machine and ensure that ADB is recognizing your device. To do this, run the following command in your terminal:

     adb devices
    

    If your device is recognized, you should see it listed.

  2. Enable wireless debugging on your phone. To do this, run the following command:

     adb tcpip 5555
    

    This will enable ADB to listen for connections on port 5555.

  3. Disconnect your phone from the USB cable and find its IP address. To do this, go to your phone's Settings > About phone > Status > IP address. Note down the IP address.

  4. Connect your phone wirelessly to your Linux machine. To do this, run the following command in your terminal:

     adb connect <IP address of your phone>:5555
    

    For example, if your phone's IP address is 192.168.1.100, the command would be:

     adb connect 192.168.1.100:5555
    
  1. Once the connection is established, you can control your phone wirelessly using Scrcpy. Scrcpy is a free and open-source software that allows you to display and control your Android device from your Linux machine. To connect to your phone using Scrcpy, run the following command:

     scrcpy
    

    This will open a new window showing the screen of your phone. You can control your phone using your mouse and keyboard.

More On Using Scrcpy

Once you have installed Scrcpy and enabled developer options on your Android phone, you can use Scrcpy to control your device wirelessly from your Linux machine.

Here are some things you can do with Scrcpy:

Display your phone's screen on your Linux machine

To display your phone's screen on your Linux machine, simply run the following command in your terminal:

scrcpy

This will open a window displaying your phone's screen. You can resize the window, control the device with your mouse and keyboard, and interact with your phone as you normally would.

Control your phone from your Linux machine

Scrcpy allows you to interact with your phone from your Linux machine using your mouse and keyboard. This can be particularly useful if you're working on an app that requires precise inputs or if you're testing a mobile game.

Record your phone's screen

You can use Scrcpy to record your phone's screen and save the output to a file. To record your phone's screen, run the following command in your terminal:

scrcpy --record file.mp4

This will record your phone's screen and save the output to a file named "file.mp4". You can stop the recording by pressing Ctrl + C.

Control your phone wirelessly

You can also use Scrcpy to control your phone wirelessly. To do this, disconnect your phone from your Linux machine and run the following command in your terminal:

scrcpy --serial <your_device_serial_number>

Replace <your_device_serial_number> with the serial number of your device. You can find the serial number in the "About phone" section of your phone's settings.

Once you run this command, Scrcpy will attempt to connect to your device wirelessly. You may need to grant Scrcpy permission to access your device the first time you run this command.

Troubleshooting

While connecting your Android phone wirelessly to your Linux machine using Scrcpy and adb is generally straightforward, you may encounter some issues. Here are some common issues and their solutions:

Issue: Unable to connect to device

If you are unable to connect to your device using Scrcpy and adb, try the following solutions:

  • Ensure that your phone and Linux machine are on the same network.

  • Make sure that USB debugging and developer options are enabled on your phone.

  • Check that your phone and Linux machine can communicate with each other by pinging your phone from your Linux machine.

  • Restart the adb server on your Linux machine by running the command adb kill-server && adb start-server.

  • If you are trying to connect to your phone wirelessly, ensure that the device is connected to the same Wi-Fi network as your Linux machine.

Issue: Poor video quality or latency

If you are experiencing poor video quality or latency when using Scrcpy, try the following solutions:

  • Reduce the resolution of the Scrcpy window by running the command scrcpy -m 1024 (replace "1024" with your desired resolution).

  • Try disabling animations and reducing the display refresh rate on your phone by going to "Developer options" > "Drawing" and selecting "Reduce animation scale" and "Force GPU rendering".

  • Close any other apps that may be running on your phone, as these can slow down the device and impact video quality and latency.

Issue: Scrcpy crashes or freezes

If Scrcpy crashes or freezes, try the following solutions:

  • Update your Scrcpy and adb versions to the latest available.

  • Close any other apps that may be running on your Linux machine, as these can impact Scrcpy performance.

  • Try reducing the Scrcpy window size or resolution.

  • If you are running Scrcpy with root permissions, try running it without root permissions instead.

Hopefully, these solutions will help you troubleshoot any issues you may encounter when connecting your Android phone to your Linux machine using Scrcpy and adb. If you still encounter issues, feel free to consult the Scrcpy documentation or seek help from the Scrcpy community.

Did you find this article valuable?

Support Adithyan A by becoming a sponsor. Any amount is appreciated!