1. Find/check the package name:
$ adb shell pm list packages | grep <package>
2. Uninstall app keeping the data and cache directories after package removal:
$ adb shell pm uninstall -k --user 0 <package>
Start a terminal emulator app on the device.
$ su
# setprop service.adb.tcp.port 5555
# start adbd
Find the IP address of the Android device. Usually, it can be found at Settings
> About device
> Status
> IP address
. In my case, IP of the device was 192.168.1.3
.
Connect the host computer to the Android device:
$ adb connect 192.168.1.3
* daemon not running; starting now at tcp:5037
* daemon started successfully
connected to 192.168.1.3:5555
To check that the device is listed in the list of attached devices:
$ adb devices
List of devices attached
192.168.1.3:5555 device
Now, both Android device and computer are ready.
Some steps are needed after the completion of all desired changes on the device.
On the host computer:
$ adb disconnect 192.168.1.3
$ adb kill-server
On the device:
# stop adbd
(Optionally) to go back to USB listening:
# setprop service.adb.tcp.port -1
$ adb devices
List of devices attached
emulator-5554 device
emulator-5555 device
To start shell
on emulator-5555
:
$ adb -s emulator-5555 shell
Settings
> Network
> Advanced
> Port Forwarding
:
Protocol: TCP
Host IP: (empty)
Host Port: 5555
Guest IP: (empty)
Guest Port: 5555
$ adb connect localhost:5555
$ adb -s localhost:5555 shell
adb | Android Studio - User Guide
How can I connect to Android with ADB over TCP? - Stack Overflow