Debugging And Running Android Application(Wired or Wireless)




Once you create any android application, first thing that you want to know is how can i run and check whether the app looks same as i wanted or there are some issues related to UI and functionality. The answer to your question is there are several ways in which you can run and debug your application. But, i am going to group them in 2 categories. First category is Debugging and Running android application using wired connections. Second category is Debugging and Running android application using wireless connection. In first category, you must need a usb cable to run the application. Android device and computer must be connected using this usb cable while debugging and running android application. But, both devices may not be connected to same WIFI network. In second category, you may need usb cable just for initial setup. Once initial setup is done, you do not need usb cable anymore. But, android device and computer must be on the same WIFI network while debugging and running android application.

If you want to know which is better, then, my answer would be debugging and running using wireless connection. The reason behind my answer is below.
a. You do not need both devices to be physically connected while debugging and running application.
b. You can move your android devices anywhere as it is not physically connected with computer.
c. There is no issue of port loosing. Connecting android device with computer several times may result in port loosing.

1. Getting Started

In this tutorial, you will learn how to debug and run android application. There are multiple ways in which you can run your application. So, let’s study under 2 categories.
a. Debugging And Running Android Application Using Wired Connection
b. Debugging And Running Android Application Using Wireless Connection




1.1 Debugging And Running Android Application Using Wired Connection

Here, you need a usb cable to run your application. steps to run the application are as below.

1. Enable Developer options

Make sure your have enabled Developer Options in your android device. If you have not enabled it, follow steps below.
a. Find Build number in the phone. Generally, it is found in below path.
Settings => About Phone => Build number.
However, this may vary depending on the android devices.
b. I am assuming that you have found the build number. Now, click on the build number multiple times. You will get a message saying that you are a developer now. If you are getting this message, then, you have successfully enabled the developer options in your device.
c. Now, Go to Developer options and click on it. Generally, you will find this option in
Settings => Developer options.
d. In Developer options, you will see a lot of options to enable/disable. Some of them are auto enabled, some are
disabled. You just need to enable the USB Debugging option.
Congrats, you have successfully configured your android device to run any android application.

1.2 Connect Device

Now, Connect your android device to the computer using USB cable.

1.3 Run application

Now, Goto to your Android Studio IDE and Click on the run icon to run the application. You will be asked to choose the device on which you want to run the application. You will also see your connected android device there. Select it and press OK.

That’s it. You will see your application running in that device.

Note: You do not need step 1 if you have already gone through it i.e. If you have already enabled Developer options. You just need to go through steps 2 and 3. However, If you have formatted your android device, then, you will have to go through step 1 again.




1.2 Debugging And Running Android Application Using Wireless Connection

There are some limitations in wired debugging. You need a USB cable to run your application. Attaching devices with a USB cable limits movement of the device. Also, it should be properly connected while debugging android application. Port connection may become loose overtime. So, if you don’t want such cases to happen, you may go for wireless debugging.
In wireless debugging, there is no need of USB cable. So, there is no limitation of device movements while debugging android application. Also, there is no point of loose connection since Android device is not physically connected with the laptop.

So, you might be thinking now what are the requirements for wireless debugging? Answer to your question is a USB cable(just for initial setup) and both the devices(Computer and the android device) must be connected over same WIFI.

1.2.1 ADB wireless debugging over wifi

Steps to use wireless debugging are as below.
1. Connect your android device with computer using USB cable. Make sure USB cable is working.
2. Open terminal(or command prompt) and type add devices. There are 2 cases now. a. First case is it will show a list of devices attached with this computer. b. Second case is it will show “command not found”. If it’s showing command not found. It means you will have to go through following steps

adb : command not found issue solution

Following steps below to solve the issue.
a. Start the terminal and go to home folder or to the folder where sdk is located.
b. Open and edit the .bash_profile file.

    
open -e .bash_profile

If you do not have .bash_profile file in your computer path, then, you need to create one using below command

touch .bash_profile

then, open and edit the .bash_profile file using above command.
c. Now, run the below command.

export PATH=${PATH}:HOME_PATH_OR_PATH_WHERE_SDK_IS_LOCATED/sdk/tools
export PATH=${PATH}:HOME_PATH_OR_PATH_WHERE_SDK_IS_LOCATED/sdk/platform-tools

Some examples are

CASE 1: 
	export PATH=${PATH}:/Applications/adt-bundle-mac-x86_64-20140321/sdk/tools
	export PATH=${PATH}:/Applications/adt-bundle-mac-x86_64-20140321/sdk/platform-tools

CASE 2: 
	export PATH=${PATH}:/sdk/tools
	export PATH=$PATH}:sdk/platform-tools

d. Then, Refresh the file using below command.

source .bash_profile
echo $PATH

Below image shows a sample example:-

Tutorialwing Android debugging and running applications

Tutorialwing Android debugging and running applications

3. Now, run below command to see the list of devices connected with the computer

adb devices

You won’t see any devices in the list as you have not connected your device yet.

4. Now, Run below command

adb tcpip 5555

5. Now, You may disconnect your android devices with the computer.

6. Now, you need to connect your add host with android device using ip address of your phone. You can find your ip address in Settings => About Phone => Status path. Run below command to connect your android device with ads hosting device.

add connect <IP address of the android device>:5555

e.g.
   add connect 192.168.1.128:5555

7. If you run the adb devices command again, you will see the list of android devices connect with the adb hosting devices(or computer).

That’s it. Now, you can execute adb commands or use Android studio or any IDE to run the android application.

NOTE: If you move to other wifi network, you do not have to go through steps 1 to 5. However, If you are switching off you phone, you will have to start again from step 1. This is because android devices lose WIFI debug mode while restarting.




Conclusion

Debugging and Running android applications can be performed using wired connection or wireless connection. In wired connection, you must need a usb cable while debugging and running application. Whereas, you do not need usb cable while debugging and running android application in wireless connection. But, Both devices must be in the same WIFI connection.
So, you can choose any option based on your feasibility.

Support Us

If you have any suggestion about this post, please comment below. We are looking for someone who helps use to make our tutorial better. Also, If you want tutorials on any topic, you can mail us at tutorialwing@gmail.com. We will try to cover the topic as soon as possible. Connect with us on Facebook, Google+, Twitter and Youtube for more updates.