Debug android with visual studio tools for unity

I have successfully connected to my android phone via wifi and I’m able to deploy apps that way ( using the default adb port 5555). However when I try to debug my app from visual studio 2015 ( Debug → Attach Unity Debugger) I just can’t connect. The ip address I enter is 100% correct. I disabled my firewall and enabled development build & script debugging. So far I tried using ports: 59694, 5555, 56580 and 56000 - with no luck. Does anyone know what port unity uses for script debugging?

You can use whatever port you want (ex: 5555). First of all, try to disable windows firewall, then in Visual Studio open “Debug”->“Attach Unity Debugger” and you should see “AndroidPlayer”. If it is the case, turn on again firewall and add new inbound rule, select program Visual Studio exe file (“devenv.exe” in my case) and allow anything. This way you can debug having firewall enabled.

I had this exact problem and went back to MonoDevelop in frustration (Edit->Preferences->External Tools). However, after a couple of reboots and successfully debugging with MonoDevelop I thought I’d try again and this time it appears to be working fine.

When you use Debug->Attach Unity Debugger it should list a second process called AndroidPlayer on a machine called @ and a port. In my case the port was 56650.

You shouldn’t need to explicitly provide an ip address.

If it still doesn’t work, worth trying MonoDevelop which works in nearly identical way.

Note that to attach your Unity app has to be running on the phone, the phone has to be enabled for debugging and you need to have used adb to connect to your phone.

For this to work your phone needs to be enabled for debugging and you need to have connected to it using adb. Have a look at steps 1, 2 and 22 (the notes).
https://www.reddit.com/r/GearVR/comments/2qcryc/step_by_step_guide_to_building_apps_for_the_gear/

I have discovered that my Unity is not opening the debugger on the default port.
For Windows 10, I opened cmd and ran:

netstat -an

In the results, look for a line like this:

TCP    0.0.0.0:56956          0.0.0.0:0              LISTENING

It’ll (probably) be in the 56XXX range. The default that VS tries to use is 56000, but mine was apparently 56956.

Use the Debug dropdown menu, Attach Unity Debugger, and change the port number to the port number you find in the netstat results.

My visual studio would not auto-detect this in the instances window, but if I manually input the port number, it just worked, and catches breakpoints and everything as expected.

There is also a current issue with an incompatibility between having Xamarin installed and using VS Unity Tools. Microsoft is on to it, see post by Sebastien [MSFT] here: Visual Studio 2015 Tools for Unity - Visual Studio Marketplace

This doesn’t work me. My VS tries to use port 56664 (I have option Attach to UNity:User-PC:56664). I have android device connected to host machine with IP 192.168.0.10. When I run Attach to Unity Debugger or Attach to UNity:User-PC:56664 nothing happens.

I thought that I had to have "Attach to UNity:androidphone:56664 " option in VS2015.

You can close your windows fire defense.
Then you can use usb debugging.(With Build setting : Develope Build and scripting)
VS Attach Unity Debug can see the list when you lunch the APK.,You can close your windows fire defense.
Then you can use usb debugging.(With Develope Build and scripting)
VS Attach Unity Debug can see the list when you lunch the APK.

Another way to get Debug log in cs files if you use the Android Device Monitor tool in Android sdk. Usually it is located in …/User/AppData/Local/Android/Tools folder (monitor.bat). This opens Android Device Monitor and if your Android device is connected, it will be listed in the device list. Here I can check the debug log.