androidadbadbwireless

Is it possible to make the wireless debugging port static?


I have a Google Pixel 7 phone using Android 13, not rooted.

Is there a way to specify a static port when doing wireless debugging, so that it doesn't change if you turn off and then turn on Wireless debugging? If it changes after reboot that's fine, I don't reboot my phone that often.

I saw people saying to install nmap and write a shell script to search for the port, I don't want to do any of that, entering and connecting to the port is easy for me via a VScode extension.

I want to make the Android wireless debugging port static, if possible.


Solution

  • 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