Taking advantage of wireless ADB debugging on MacOS for Android 10 and lower
One of the many issues encountered by developers using Android Studio is the amount of CPU power consumed by Android Studio’s emulator. On my Macbook for example, I can hear my CPU fans going crazy as the emulator boots up and with every passing time, my battery percentage dwindles rapidly. The reliance on the emulator can further be exacerbated by either a poor USB cable connection or avoidance of having to have a cable always connected between physical device and laptop. I share these two issues and this article will explain how wireless debugging has made things easier for me.
This article is mainly for Mac users and assumes you have the platform-tools already installed through Android Studio.
About ADB
The Android Debug Bridge (ADB) is a command-line tool that lets you communicate with a device. Through this connection, you can perform functions such as installing and debugging your apps as well as be able to run via a Unix shell a variety of commands on the device.
Your physical device
To allow ADB to be able to connect to the physical device and perform debugging actions, you will need to enable USB Debugging in the system settings under Developer Options. If you do not see the Developer Options menu, you need to enable this by tapping on Settings > About phone > Build number seven times. A toast will be displayed to confirm that the setting has been enabled and you will then see the Developer Options menu on the previous screen at the bottom.
Setting up ADB
Before running the following, to check that ADB is working or not simply open a terminal window and run the following:
adbIf ADB command is not set up you will get the following error:
-bash: adb: command not foundIf you get the above error, you may proceed with the below instructions on how to set up the ADB command.
To be able to run the ADB command globally on your laptop run the following commands to add platform-tools to the path.
In the open a terminal window type the following:
$ echo 'export ANDROID_HOME=/Users/$USER/Library/Android/sdk' >> ~/.bash_profilepress Enter and then:
$ echo 'export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools' >> ~/.bash_profileand also press Enter.
Update the bash_profile file to activate the above changes:
source ~/.bash_profileand press Enter.
You can then run the ADB command again to determine if the above has worked. If it is configured correctly the following will be displayed:
$ adbAndroid Debug Bridge version 1.0.41Version 30.0.4-6686687Installed as /Users/yourusername/Library/Android/sdk/platform-tools/adbglobal options:-a listen on all network interfaces, not just localhost-d use USB device (error if multiple devices connected)-e use TCP/IP device (error if multiple TCP/IP devices available)-s SERIAL use device with given serial (overrides $ANDROID_SERIAL)-t ID use device with given transport id-H name of adb server host [default=localhost]-P port of adb server [default=5037]-L SOCKET listen on given socket for adb server [default=tcp:localhost:5037]...
Setting up the wireless connection
Connect your physical device to the laptop via USB and be sure to allow your laptop to connect to the device via the following dialog (if it pops up on your physical device):
With your physical device still connected via USB to the laptop run the following command from the terminal:
adb tcpip 5555if successful the following will be displayed:
restarting in TCP mode port: 5555if not and you have an emulator open on your laptop or more than one device connected to your laptop:
error: more than one device/emulatorsimply close any other emulators you have open on your laptop and ensure that your physical device is the only device to be detected by ADB.
Next you will need to determine the IP address of your physical device. For the wireless debugging to work both the laptop and the physical device need to be on the same wireless network. Determine the IP address of your physical device by going to Settings > About phone (or About tablet) > Status > IP Address.
Then using the IP address for your physical device type the following into the laptop terminal:
adb connect your_device_ip_addressYour physical device may display another prompt like the following again:
to which you can allow by clicking OK.
To determine if your laptop and physical device are connected wirelessly, run the following command in the terminal:
adb devicesif successful the list of the devices displayed will include both the USB connection as well as the WiFi connection respectively:
$ adb devicesList of devices attached
111143522b1c7ece device
your_device_ip_address:5555 device
if not successful one of the devices listed may display an “unauthorized” next to it:
$ adb devicesList of devices attached
111143522b1c7ece device
your_device_ip_address:5555 unauthorized
if this happens simply restart the ADB process and try the reconnection steps by running the following command from the terminal:
adb kill-serverthen:
adb connect your_device_ip_addressOnce you run:
$ adb devicesand each device listed — the wirelessly connected as well as the USB connected — says “device”, you may disconnect the USB cable as the wireless connection has been successfully established between your laptop and physical device.
