Time: 10-15 mins
Prerequisites: Basic android development relating to USB debugging
Traditional USB debugging
When we get around to testing the android applications its usually faster and convenient to use an actual mobile to test the apps. But Android Studio 2.0’s instant run feature might change that.
So as google has given a comprehensive guide here, we can set USB debugging up and run the applications directly on our device.
But it always seemed to be kind of a pain to have the mobile always connected to the computer via USB. Especially if we had the misfortune of having a really short or loose cable.
When I was working on transferring data from a microcontroller to the mobile I discovered that there was a “Handsfree” way of doing this.
Wirelessly Debugging
So the idea here is that both the computer and the android device connects to the same network and so we can have a adb connection to the Android-powered device over that network.
You can find the adb tool in /platform-tools/. You can add that to your System Variables - Path variable, after which you can run adb shell
and other commands easily from your command line once your android device is connected by USB to your computer.
Or you can start the command line in the platform-tools folder itself to run adb (Android Debug Bridge) commands.
So as shown above we can use the adb shell
command to find the IP address assigned to the device by the router both the computer and the android mobile is connected to.Here it’s seen to be 192.168.1.34
. You can also see it from your mobile’s wifi settings.
Once we have access to the adb and know the ip address of the mobile device, run the following commands in order.
adb tcpip 5555
adb connect <device-ip-address>:5555
In case you get a error saying its unable to connect use adb usb
to restart the connection.
Once you see connected to 192.168.1.34:5555, you can now remove the USB connection and still be able to run app’s onto the mobile from Android Studio.
As you can see the device is recognized by the Device Chooser dialog box both via the USB connection and the network connection.