Wednesday, July 30, 2014

Connecting to android emulator running on another PC for debugging

If you have more than 1 system you might want to use one to run eclipse and probably the other to run the android emulator. This is a good idea since the android emulator ,along with eclipse, can take up reasonable amount of resources. Running them separately will ease the workload. You can use the steps below to connect to an android-emulator or an instance of bluestacks running on another machine.

1. In the machine where you want to run the emulator, download and install FreeSSHd from http://www.freesshd.com/
 (Select No in the messagebox asking if you want to install it as a system service. )
2. Open up FreeSSHd and under the Server status tab check if the SSH server is running. If not,
      a. Select the SSH tab and change the port to something else (for eg: 27).
      b. Click Apply.
      c. Now go back to the Server status tab and start the ssh server.


3. Select Tunneling tab tick mark both Allow local port forwarding and Allow remote port forwarding and click Apply

4. Go under Users tab. Click Add
5. Enter a username
6. Select Password stored as  SHA1 hash in the Authorization drop down menu
7. Enter a password
8. Tick mark Shell, SFTP and Tunneling under the Users can use section.
9. Click OK and then Apply

10. Start the emulator or bluestacks

11. Now, on the machine you have installed eclipse, download and install Putty from http://filehippo.com/download_putty
12. Open up putty. Under Connection ->SSH->Tunnels, select Local and Auto
13. Against Source port enter 5555 and against Destination enter localhost:5555. Then click Add
14. Do the same with Source port 5554 and Destination localhost:5554

15. Go to Session, Select SSH and enter the ip address of the machine where you installed FreeSSHd and the port you set in step 2. (Read step 1 in http://coditivity.blogspot.in/2014/07/how-to-do-port-forwarding.html to learn how to find out your internal ip address)
16. Under Saved sessions enter a name and click Save
17. Click Open

18. Enter the username and password you entered in steps 5 and 6 respectively.
19. Open up the command prompt.
20. Change the directory to the one where adb.exe is located
21. Enter adb kill-server followed by adb start-server
22. If you want to connect to Bluestacks, enter adb connect localhost
23. Enter adb devices and you will see that the available devices are listed

Start eclipse and you will be able to debug against this device.

NOTE : Make sure that the firewall isn't blocking the connection attempts by putty and FreeSSHd.