Remote Wireless Debugging

Ahmet Can Ogreten
8 min readNov 6, 2022

Hi,

This might be an update on my previous article, Remote Debugging (Remote USB Device). However, since I see it as a significant improvement on the debugging problem I have, I decided to make it a separate article.

First of all, I lied. It is not completely wireless. You will need to connect your android device to a computer for the first time. Then, it is completely wireless.

I explained the problem I had in my previous article. Nevertheless, let me summarize it again. I want to be able to debug a mobile application that is installed on a mobile phone that I don’t physically have access to. For example, perhaps I have a customer in another country who is facing some problems that I couldn’t experience myself. In that case, I would like to be able to remotely debug their mobile application on their mobile phone as if their phone is connected to my USB port. This way, I can run the code step-by-step and also have access to logs, variables, and other debugging information. Hopefully, I will be able to find the root cause of the problem and help my customer.

Let’s move toward the solution step-by-step, explaining the tools we will be using along the way.

ADB (Android Debug Bridge)

is a command-line tool for communicating with android devices. This is how we can install our mobile application and debug it on those devices. To install ADB, you can follow this tutorial though you probably already installed it if you are developing android applications.

ADB uses the client-server architecture. However, it has a so-called daemon entity in addition to the client and the server.

The daemon (adbd, ADB daemon) runs as a background process on each device, which is the actual entity that runs commands on the device.

The client (ADB client), on the other hand, runs on the desktop or laptop computer that we use as a development computer. It will send commands to the server that will be executed by the daemon on the device.

Where does the server live in this case? The server (ADB server) lives on the development machine as well. It is responsible for managing all the connections.

ADB has a feature called wireless debugging. It allows you to debug your mobile application wirelessly instead of plugging in your mobile phone into your computer using a USB cable. However, for the first time, you need to plug your phone in using a USB cable.

Before we start, make sure you activated developer settings and from there activated USB debugging. If there is a “Wireless ADB debugging” option, make sure you activated that as well. If you don’t know how to activate these on your mobile phone, you can search on Google for the model of your mobile phone. There are tons of tutorials that will show you how to do it.

Now, plug your mobile phone into your computer. Your mobile phone will show you a pop-up asking you if it should give access to USB debugging. It will look similar to the pop-up below. Make sure you give access.

This setup is how we debug our mobile application on physical devices. If I need that this is how I would do it. Open VSCode or Android Studio, and debug my application.

However, we need to debug our application wirelessly. For this, we need to tell our mobile phone that we will try to connect to it over the network using TCP/IP protocol. Now, we are preparing our mobile phone for the connection and that’s why we need to connect for the first time. For this, your computer and your mobile phone must be on the same network. We will break this barrier after we achieve connecting from the same network so bear with me.

From now on, we start using a little bit of terminal. I will show the commands in Windows. That’s because my customers usually use Windows. Linux and macOS people can probably adapt these to their environment anyway.

After you downloaded platform tools for Android, open that folder. There should be an executable file called adb. In that folder, hold the shift key and right-click somewhere in that folder. There will be an option called “Open PowerShell window here” or something similar.

To be safe, let’s check if we are on the same network and can communicate with the mobile phone. For this, we need the IP assigned to the mobile phone. You can find your IP under settings About Phone -> Status Information. Or just search IP in your settings. If you couldn’t find it, there are applications on the play store that will show you this information. Just search for IP. If you install such applications, remember we need internal IP which will look like 10.x.x.x or 198.x.x.x.

After finding out the IP address of our mobile phone, we will ping it. That is, check if the computer can have a path to access the mobile phone.

The IP of the mobile device I have is 192.168.43.17. I will ping it by typing

ping 192.168.43.17

If we can see lines starting with “Reply from”, it means everything is in place. Our computer and mobile phone can talk to one another.

Now we need to tell our mobile phone to prepare itself and listen to our requests since we will connect to the mobile phone wirelessly. To do this we will use adb

.\adb.exe tcpip 5555

This command will tell the mobile phone that we will try to connect you on your port 5555, prepare yourself.

If it tells “restarting in TCP mode port: 5555”, it means it understood and prepared itself.

Now we can unplug our mobile phone from our computer. Let’s try to connect to it without USB. We will, again, use adb for this

.\adb.exe connect 192.168.43.17:5555

Here we are asking to connect our mobile phone on port 5555. Do not forget to change the IP address to your mobile phone and the port if you asked to use another port in the previous step.

As you can see, it said failed to authenticate on the first try. This is not an error. If you see this as well, check your mobile phone. There will be a pop-up waiting for you to allow the connection. After allowing it, I re-run the command and it said, it was already connected.

See, my computer recognize my mobile phone as it was directly connected to my USB port. I can install and debug my application without using a USB cable. I think this is already very helpful since it frees you to keep your mobile phone connected to the computer. I don’t know you but I remember many times that my connection was lost since I had to move my computer and debug at the same time. I say, no more.

Now that we achieved wireless debugging while the development computer and the mobile phone are on the same network, let’s try if we can achieve this without them being on the same network.

I lied, again. There is no way (until communication through smoke is possible which in a way is also a public network but anyways) to debug your mobile app without a network between your development computer. However, this network does not need to be a Wi-Fi or physically close network. That’s the beauty. We can create a virtual network that contains a computer from China and a smart toaster from Canada. Yes, we will use a VPN.

I will explain the whole idea now if you already have a VPN or know what you are doing. Then show you how to do it by using a free VPN, Tailscale (It is actually freemium but for our purpose free is more than enough).

  1. Connect your mobile phone to some computer through USB that has adb installed.
  1. Then, run the command below to make your mobile phone listen on a TCP port of your choice for debugging.
.\adb.exe tcpip <port>

Make sure you get “restarting in TCP mode port: <port>” response.

3. Now you can disconnect your mobile phone.

4. To connect to the mobile phone, your development computer and mobile phone should be on the same network. If not, we need VPN. Connect to the same network through VPN. VPN connected devices will have a separate IP assigned to them so that other devices connected to the same VPN can access them. Thus, mobile phone and development computer will have VPN ips assigned to them. You will find these IPs in your VPN settings. If you are not using your own VPN, I will show you how you will these IPs with Tailscale.

5. Connect to your mobile phone using adb and its <mobile-vpn-ip>

adb connect <mobile-vpn-ip>:<port>

6. Now, you are connected as if you plugged your mobile phone using USB.

That’s the idea. If you have a VPN service that you are already using, use it. If not, let’s use Tailscale. There are alternatives. I tried ZeroTier and Tailscale since they have android applications and find Tailscale better. If you find something better let me know.

Tailscale

Don’t worry, this part will not be that long. First, go to Tailscale’s website and create an account. After that, you need to download and install Tailscale on your android device and your development computer.

After you install those applications, you can see your virtualized network on both applications or on the website. Also there, you can find IPs that can be used to connect to your devices inside the VPN.

Yes, you are right. We will be using the IP listed for our mobile phone to replace <mobile-vpn-ip> in the previous steps.

That’s it. This is how we can remotely, and wirelessly debug mobile applications on Android. For me, debugging android phones was enough so I didn’t look into how to debug remotely iPhones. Let me know if you find a solution that will allow us to debug iPhones as well or simply say that you wish there were a way to do this in iPhone. Who knows, maybe we can figure it out :)

Thanks for reading. If you benefit from this article leave a comment or clap which would motivate me to create more articles of such content. Have a nice debugging.

--

--