androidandroid-studioandroid-11adbwirelessandroid-12l

Android 11+ Wireless Debugging not available when using Mobile Hotspot as the network


Before android 11, i was able to wirelessly debug apps using this method

  1. turn on the mobile hotspot in the (target) android phone
  2. connect the computer to the hotspot
  3. run adb tcpip 5555
  4. adb connect [ip of the target phone]

The problem is Android 11 introduced Wireless Debugging and the above method doesn't work as expected. And the wireless debugging mode cannot be turned on unless my android phone is connected to wifi so it is not working because I want to use the target phone's hotspot for wireless debugging.

is there any possible solution? or is it possible to turn the wireless debugging mode ON even if the phone is not connected to wifi?


Solution

  • Work Around

    1. run adb tcpip 5555
    2. run adb connect [ip]
    3. for android 11 and 12 go to Settings/Display & brightness/Auto screen off and make it 30 minutes. (means that your phone won't auto lock so it will stay wirelessly connected to ADB)

    - android 13 and above do not disconnect you if your device gets locked

    - I hope android engineers will allow using the wireless debug feature without being connected to WiFi in newer versions of android though, as pointed to in the question.

    Bonus info:

    Your phone has two ip addresses, one from your Internet Provider (in Settings/About/Status) that changes whenever you turn off your Mobile Data and one that your hotspot creates as a router (you can get it from your PC when you connet to your phone's hostpot) that does not change (sometimes does change if you restart your phone, though

    macOS: after step 1 above, if you run netstat -nr | grep default you will get the router's (Your phone in this case) ip address in the first line 'default gateway' (For windows ipconfig in cmd)


    Mac only

    I also made aliases for the terminal

    alias adb_s='adb tcpip 5555'
    alias adb_sc='adb tcpip 5555 && adb connect $(netstat -nr | grep default | awk '\''$2 ~ /\./ {print $2}'\'')'
    alias adb_c='adb connect $(netstat -nr | grep default | awk '\''$2 ~ /\./ {print $2}'\'')'
    

    Now, when i run (single command):

    adb_sc = device starts in tcpip mode and gets connected wirelessly 
    adb_c = device gets connected wirelessly if already in tcpip mode
    adb_s = device starts in tcpip mode
    

    You can copy the aliases above into .zshrc {/Users/[your-username]/.zshrc (for zsh terminal)} file and can enjoy the convenience as well.