2

I have 2 Android 14 phones. Both have Wireless Debugging enabled. Both are paired with the adb server PC. All devices are connected to the same WLAN. One of the phones always uses a static port in IP Address & Port menu entry. The other does not, it always randomizes the port. Network & Debug Networking options are the same for both phones.

How to I make it keep the port static on phone (NOT with adb tcpip, it will not work in this case at all)?

Phones:

  1. OnePlus 8 Pro (instantnoodlep, IN2020 CN), Android security update 2024-09-05 - uses dynamic port
  2. Motorola moto g(7) plus (lake), Android security update 2024-09-05 - uses static port
tsilvs
  • 375
  • 4
  • 17

2 Answers2

2

One of the temporary workarounds could be this:

# 1. Connect to your phone with the current dynamic port over WLAN

sudo adb connect $ANDROID_DEVICE_WLAN_IP:$PORT

2. Set a static port for the device. Be quick before it changes!

sudo adb -s $ANDROID_DEVICE_WLAN_IP:$PORT tcpip $PORT

3. Now reinitialize the connection. You will be able to use this static IP until phone reboot.

sudo adb disconnect $ANDROID_DEVICE_WLAN_IP:$PORT sudo adb connect $ANDROID_DEVICE_WLAN_IP:$PORT

4. Now run anything you need to run on your phone. E.g. list all of the packages installed for a user

sudo adb -s $ANDROID_DEVICE_WLAN_IP:$PORT shell cmd package list packages --user 0

You'll need Android 12+ device & android-tools (or platform-tools) version >=35.0.1

tsilvs
  • 375
  • 4
  • 17
1

It's very annoying. I created this script to automate most things (except IP) on MacOS

https://gist.github.com/woutervanwijk/71c9d36cf38544c99f4b5399ca80fea3

Touwer
  • 111
  • 1