How to Set Up and Use ADB Wirelessly With Android

enable/disable ADB via WiFi on Android without root and with root.

ADB provides a command line to establish an advanced connection between android and Windows or MAC PC. Usually, we use USB cables to connect Android to PC to use ADB commands. But you can also Use ADB wirelessly with Android. All it needs wifi and a PC. This guide explains the steps to set up and use ADB wirelessly.

Use ADB Wirelessly With Android- How to Setup
Set Up and Use ADB Wirelessly With Android

ADB command line is used to make changes to your android device that are not available on the device. An ADB connection gives you the advantage of altering the default Android settings that are usually not possible to use on the phone.

Tasks like removing system apps, rooting the device, Uninstall bloatware, changing MAC address,and OTA Update etc require ADB access on the device. The typical ADB connection is established using a USB cable to connect android to a windows PC or MAC.

But, you can also use ADB commands wirelessly by establishing an ADB connection to PC via wifi.

Setup ADB to use Wirelessly(Over Wifi)

In order to use ADB wirelessly with android, we need to make some changes to android settings before using the ADB commands to make changes on android via ADB.

If you have already set up ADB on your Android and PC, then you can skip this step. If you haven’t, there is a first time for everything!

In order to use ADB on the system, you require to download Android SDK Platform tool. MAC Users can use Homebrew to install ADB using the command:

brew install homebrew/cask/android-platform-tools

Follow the steps to Setup WiFi ADB on Android:

Prerequisites

  1. Android > 11 (or have an option to enable ADB Wifi from within the Settings of your phone)
  2. You need to be connected to a Wifi (you don’t need internet access though)
  3. Tasker (obviously)
  4. WRITE_SECURE_SETTINGS and READ_LOGS permissions granted to Tasker (this tool may be very helpful)
  5. Termux (I highly recommend the F-Droid version due to the updated repository!)
  6. Termux:Tasker

Preparation

Whenever a popup comes up asking for confirmation of Wifi ADB connections, etc., you obviously have to accept it. I can’t recall in detail when they might show up.

In the past, I’ve been using AutoInput to auto-accept them, but I disabled it because I didn’t want to have AutoInput scan my screen all the time for these popups. And I couldn’t find a reliable Logcat entry.

Installation of android-tools within Termux:

  1. open Termux and enter the following command;
    pkg install android-tools
  2. you may have to confirm the installation by pressing y during the setup.
  3. check if adb is working by just typing adb

Create folderstructure and first script to be executed by Tasker

  1. open Termux
  2. create the folder-structure by entering following command;
    mkdir -p .termux/tasker

    (don’t forget the “.” in front of termux)

  3. Now create the script by typing
    nano .termux/tasker/adb.sh
  4. Here paste the following script into nano
#!/data/data/com.termux/files/usr/bin/bashhost="$1"adb=$PREFIX/bin/adb$adb connect $host$adb tcpip 5555$adb disconnect$adb kill-server

!/data/data/com.termux/files/usr/bin/bash

Save the script by selecting CTRL (in Termux) and then pressing “x” – confirm by pressing “y”

Create a second script for pairing Termux with Wifi-ADB

  1. open Termux
  2. create the script by typing
    nano .termux/tasker/adb_pair.sh
  3. paste the following script into nano
    #!/data/data/com.termux/files/usr/bin/bashhost="$1"code="$2"adb=$PREFIX/bin/adbecho $code | $adb pair $host$adb kill-server

!/data/data/com.termux/files/usr/bin/bash

Save the script by selecting CTRL (in Termux) and then pressing “x” – confirm by pressing “y”

Allow Tasker to run Commands in Termux environment

  1. open android settings -> Apps -> Tasker -> permissions -> additional permissions
  2. grant permission to “Run commands in Termux environment

Import of profiles and tasks in Tasker

I first thought I’d explain how to set it up manually. But actually, this would take too much time. So I provide you with my profiles: Taskernet Download

Explanation and how to use the profiles

Pairing yourAndroid to Wifi ADB

  1. Disable all profiles in the project and only enable the profile ADB_Pairing (Long Press Volume Up)
  2. Navigate to Android phone settings -> developer options -> Debugging over WLAN ->
  3. Pair device with pairing code (or something like this)
  4. With the pairing code and IP:Port shown, press and hold Volume UP.

This will call the adb_pair.sh script created previously and send the pairing code and IP:Port to Termux, which will then pair with your device. Finally, a flash message will be shown with your IP:Port and pairing code as a kind of confirmation. The profile will then be disabled because you won’t need it anymore.

If everything went fine, you should now find at least one paired device at the “Debugging over WLAN” settings screen. (most likely named xxx@localhost)

Now disable Wifi ADB from the settings again.

How the other profiles work

I’ve created three more profiles. You should enable the first and third profiles. The second profile will be enabled on device startup. I will explain what the different profiles do and how to make use of them.

1_Set Var on Boot

This profile runs on device boot and simply sets the variable %ADB_enabled to 0 and enables the second profile 2_enable ADB Wifi

2_enable ADB Wifi

This profile runs on device unlock. With this profile, I will check for how long the device is enabled (I’m waiting for at least 60 seconds to make sure everything is settled after device boot) and that the variable %ADB_enabled is set to 0.

If both conditions are true I’m enabling the global setting Debugging over WLAN.

3_Get Port (Logcat) + Exec Termux

Now I’m checking Logcat for adb wifi entries. Once it found one we will extract the port and use it with the script adb.sh. The script will then connect to Debugging over WLAN and run adb tcpip 5555 to enable ADB Wifi.

Afterwards we wait 2 seconds and check if ADB-Wifi is enabled. If it was successful (%has_adb_wifi == true) tasker will say that to us and disable “Debugging over WLAN” (because it’s not needed anymore). Furthermore, we disable the second profile (because I don’t want this to be run every time I unlock my phone) and change the %ADB_enabled variable to 1.

Final Words:

Enabling Wifi ADB on Android allows you to use ADB commands on android wirelessly. Cherry on the cake, you are not required a working internet connection to use ADB wirelessly on android. All the latest Android phones running on Android 11 or later are capable of wireless ADB. All you need is a working wifi adapter to connect the PC and android together wirelessly. 

WHAT TO READ NEXT?