- Home /
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?
Did you get your debug working? how do you did? I am having same problem
Answer by jules43 · Oct 07, 2015 at 08:21 AM
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/
$$anonymous$$isher's answer is also very helpful. You also need the firewall to allow devenv.exe through the firewall.
Answer by misher · Mar 01, 2017 at 07:15 AM
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.
Answer by pgilmorepf · Jun 18, 2016 at 05:38 AM
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.
Be careful that you don't just pick any 56xxx port thinking it will be for your connected Android device.
In my case, the only 56xxx port listening was the Unity Editor, on port 56544: e.g. E:\dev\android-sdk\platform-tools>netstat -an
Active Connections
Proto Local Address Foreign Address State
TCP 0.0.0.0:56544 0.0.0.0:0 LISTENING
and in VS: (Debug->Attach Unity Debugger)
Ins$$anonymous$$d, you should be able to see your Android device in the debugger if you try an adb tcpip & connect. e.g. running an AVD emulated device, (which uses localhost as the ip address)
E:\dev\android-sdk\platform-tools>adb devices
List of devices attached
emulator-5554 device
E:\dev\android-sdk\platform-tools>adb tcpip 5555
restarting in TCP mode port: 5555
E:\dev\android-sdk\platform-tools>adb connect localhost
connected to localhost:5555
E:\dev\android-sdk\platform-tools>adb devices
List of devices attached
localhost:5555 device
emulator-5554 device
On starting your Unity AP$$anonymous$$ in Android (built with Development Build+Enable Scripting), you should see an extra entry in the VS Debug->Attach Unity Debugger list: e.g.
Even with Android running the Unity AP$$anonymous$$, netstat did not detect that port # as listening or otherwise: E:\dev\android-sdk\platform-tools>netstat -an | findstr "56014"
E:\dev\android-sdk\platform-tools>
Similarly, for an actual Android device:
E:\dev\android-sdk\platform-tools>adb devices
List of devices attached
03157df3d86de113 device
E:\dev\android-sdk\platform-tools>adb tcpip 5555
restarting in TCP mode port: 5555
E:\dev\android-sdk\platform-tools>adb connect 192.168.0.5
connected to 192.168.0.5:5555
E:\dev\android-sdk\platform-tools>adb devices
List of devices attached
192.168.0.5:5555 device
03157df3d86de113 device
Then run the built AP$$anonymous$$ in Android, and VS Debug->Attach Unity Debugger list shows:
Annoyingly, at the moment, VS debug breakpoints & stepping are only working for me with a real device, not with the AVD emulated device...
Interestingly, while debugging on the real Android device, netstat -an shows an established connection:
TCP 192.168.0.38:10742 192.168.0.5:56453 ESTABLISHED
Answer by goneale · Jun 27, 2016 at 01:48 PM
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: https://visualstudiogallery.msdn.microsoft.com/8d26236e-4a64-4d64-8486-7df95156aba9
Answer by playerone00 · Oct 10, 2016 at 09:21 PM
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.
I agree, it doesn't always work. I've had spans of time where it works great, and spans of time where it won't work at all, and I haven't deter$$anonymous$$ed the independent factor.
I have found that if I have too many ports open in other programs, then VS still can't connect, even if I give it the right port number. In my case, I usually run Jenkins and sometimes Apache on my local machine. I have found it quite reliable, that if it won't connect even with the correct port, then disable everything of this nature, including browsers, and then it will connect the debugger. Don't even have to restart visual studio.
There might be something in the unity vs tools plugin that only searches a fixed number of open ports, and gives up if there's too many.
@pgilmorepf Hi, Can you please exactly tell, what do you mean by disable everything of this nature including browser, What sort of things you meant and which browser?, are you talking about web browser?
Your answer
Follow this Question
Related Questions
How do you Debug Unity Player Builds? 0 Answers
Problem debuging code using VisualStudio 2017 and Unity2019.1.0a10 1 Answer
How do you get OutputDebugString to show up in the Visual Studio output window? 0 Answers
Impossible to use Visual Studio 2015 Debugger anymore (Unity 5.2.1f) 2 Answers
Visual Studio 2015 debugger can no longer attach to Unity after installing RC3 1 Answer