Run/install/debug Android applications over Wi-Fi?

前端 未结 30 1636
[愿得一人]
[愿得一人] 2020-11-22 07:16

I thought there was a way to test your applications in development over Wi-Fi. Is this possible?

I\'d love to be able to untether my phone and develop wirelessly.

30条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 07:47

    Though there are so many good answers, here is my two cents for the future me :P and for anyone who wants it quick and easy.

    For Mac:

    • connect the device using USB first and make sure debugging is working. Disconnect any other devices and quit emulators.
    • open terminal and run the following script

      adb tcpip 5555
      adb connect $(adb shell ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}' | cut -d: -f2):5555
      
    • disconnect USB connection and the device should be available for WiFi debugging

    Explanation:

    adb tcpip 5555 commands the device to start listening for connections on port 5555

    adb connect $(_ip_address_fetched_):5555 tells to connect on port 5555 of the _ip_address_fetched_ address

    where _ip_address_fetched_ includes following:

    adb shell ifconfig getting internet configurations using adb shell

    grep "inter " filter any line that starts with inter

    grep -v 127.0.0.1 exclude localhost.

    At this point, output should be like:

    inet addr:###.###.#.### Bcast:###.###.#.### Mask:255.255.255.0

    awk '{print $2}' get the second part of the components array, separated by space (I'm using zsh).

    The output up to this point is

    addr:###.###.#.###

    cut -d: -f2 split the string by delimiter : and take second part. It will only take your device IP address

提交回复
热议问题