Attaching Monodevelop debugger to an Android device?

Hi,

Has anyone had any success with this?

Googling around for solutions, a good few people seem to have problems, but there’s no real answers… The closest thing to an answer is this:

There’s suggestions that you’ve got to connect ADB via TCP/IP (adb tcpip/adb connect commands). Using this I can get ‘adb logcat’ output fine over wifi - but I still can’t attach the debugger - Monodevelop just doesn’t see an Android build, just the editor.

(And yes, it’s definitely a development build with script debugging enabled)

So far I’m deploying the app via USB, then switching ADB over to TCP/IP - as the project fails to deploy from Unity over TCP/IP, it hangs indefinitely on the progress bar. Does this make a difference?

Any other ideas on how to make this work? (How is Monodevelop actually attempting to find the Android device?)

Yes, you can attach the MonoDevelop debugger to an Android device with ADB via TCP/IP. The process is described below.

  1. Enable “USB debugging” on your device and connect the device to your development machine via USB cable. Ensure your device is on the same subnet mask and gateway as your development machine. Also, make sure there are no other active network connections on the device (i.e. disable data access over mobile/cellular network).

  2. On your development machine, open up your terminal/cmd and navigate to the location of the ADB. You can find the ADB tool in /platform-tools/

  3. Restart host ADB in TCP/IP mode with the following command:
    adb tcpip 5555

This should produce the following output:
restarting in TCP mode port: 5555

This will have enabled ADB over TCP/IP using port 5555. If port 5555 is unavailable, you should use a different port.
(See Android Debug Bridge (adb)  |  Android Studio  |  Android Developers)

  1. Find out the IP address of your Android device (Settings → About → Status) and input the following command:
    adb connect DEVICEIPADDRESS
    (DEVICEIPADDRESS is the actual IP address of your Android device)

This should produce the following output:
connected to DEVICEIPADDRESS:5555

  1. Ensure that your device is recognised by inputting the following command:
    adb devices

This should produce the following output:
List of devices attached
DEVICEIPADDRESS:5555 device

  1. Build and run your Unity application to the device. Ensure you build your application with Development Build flag enabled and Script Debugging turned on.

  2. The device no longer needs to be connected to your development machine via USB.

  3. Finally, while the application is running on your device, open your script in MonoDevelop, add a breakpoint, select “Run” → “Attach to Process” and select your device from the list. (Note that it might take a few seconds for the device to appear in the list. It may not appear in the list if the application is not running or if the device’s display goes to sleep).

For some more details and for troubleshooting, see the Wireless Usage section in the Android developers guide for the ADB: http://developer.android.com/tools/help/adb.html#wireless

NB:
The device sends multicast messages and the editor and MonoDevelop subscribe/listen for them. For this to work, your network will need to be setup correctly for Multicasting.

2 Likes

I’ve tried running through all the steps you’ve listed above, and the best I can get is the same result as the original poster. I’m able to connect to my device over Wifi (and even get live logcat). But I can never seem to get the Android process to appear in ‘Attach to Process’.

i’ve tried both connecting my iMac and Android device to the same Wifi and also setting up a shared Wifi connection from my iMAC over wifi.

In both cases Step 8 is the blocker, since there is no process akin to an Android device running the build. I’ve confirmed that the apk was built using Scrip Debugging and Development build.

Any suggestions as to what I may be doing wrong?

Same problem. I enabled multicast on my router. Step 8 also implies that my app actually runs, and I have the time to set and hit a breakpoint. My bug is somewhere in startup, and I have no idea where, I was hoping the debugger would would crash-out to the problem.

I am having the same problem of not seeing my device in MonoDevelop…

But… If you have an Android device, you may be able to “Select the app to be debugged” and enable “Wait for debugger” in your Android Developer options. When you start your app, it will immediately block waiting until the debugger attaches. These options are available on my Samsung Galaxy S5 (Lollipop).

Hi, I have the same problem. I’m on Mac OSX 10.8.5, MonoDevelop 4.0.1, Samsung Galaxy Note 4, Android 4.4.4 and adb adt-bundle-mac-x86_64-20140702… The device is connected (adb devices command shows : 192.168.1.115:5555), Muy build is in Unity 4.6.4, the build flags “Development Build” and “Script Debugging” are on… but when I run the app in the device, Mono is not showing the device in the “attach to process” list.

UPDATE: Same also for me. adb logcat is working perfectly…

Did anyone find a way?!!!

Same problem. Monodevelopment editor, “Run”-> “Attach to Process” only get Unity Editor. Development Build and Script Debugging checked. Turned off firewall on PC and router. I was able to debug in Android a few weeks ago with the same router setting and Android phone. So the router multicast is working.

I’m running:
Windows 8.1
Unity 64bit, 5.1.1f1 (just downloaded a fresh copy)
Android Debug Bridge version 1.0.32 (Android SDK from about 3 to 4 weeks ago. Don’t remember the version I used this version to debug to Android before)
Android Developer options: Stay awake and USB debugging. also tried “Select debug app” to the Unity app.

adb devices is showing 192.168h.2.8:5555 (IP of Android phone )
I can build and download to the Android device over TCP/IP
adb logcat is working. I get full logcat verbose on the Windows dev system.

Am I missing something? I’ve been working on this for hours. Tried all kinds of stuff. Plugged in to USB, unplugged. reboot, download new Unity build. checked router settings, etc.

I’ve also tied Revoking USB debugging authorizations. I then plugged the USB in and granted authorization. Kill adb server and started over with adb. adb tcpip 5555, adb connect 192.168.2.8, When this connection is made Android again asks for authorization for this connection. I granted it. Logcat works, “Attach to Process” does not.

I notice when I use: “adb tcpip 5555” this is the output:

Z:\AndroidSDK\sdk\platform-tools>adb tcpip 5555

  • daemon not running. starting it now on port 5037 *
  • daemon started successfully *
    error: device not found

Z:\AndroidSDK\sdk\platform-tools>adb connect 192.168.2.8
connected to 192.168.2.8:5555

Notice port 5037. I assume this is daemon port on my Windows system. Port 5555 is on the Android.

So I try:
Z:\AndroidSDK\sdk\platform-tools>adb tcpip 5037

  • daemon not running. starting it now on port 5037 *
  • daemon started successfully *
    error: device not found

Z:\AndroidSDK\sdk\platform-tools>adb connect 192.168.2.8
connected to 192.168.2.8:5555

The Android phone still connects to 5555. I disconnect: adb disconnect 192.168.2.8 and try:

Z:\AndroidSDK\sdk\platform-tools>adb connect 192.168.2.8:5037
unable to connect to 192.168.2.8:5037:5037

but this works:

Z:\AndroidSDK\sdk\platform-tools>adb connect 192.168.2.8:5555
connected to 192.168.2.8:5555

Does anyone know what the 5037 port is? Do I have to connect the Android phone to port 5037? If I do then how do I connect to another port then 5555?

Please can Unity give us more then “Attach to Process” and it will magically show up. Is there a command line to try? Any setting in Unity to test or show adb process? How does the “Attach to Process” work? does it establish process connections when the editor first runs or does it continually try to establish connections? Is there any adb commands to test? The Windows dev system is talking to logcat just fine.

Don’t know what else to do. Keep coding and hope “Attach to Process” magic will just start to work again. Bummer.

1 Like

Still no answer for this? I am also stuck with the same problem for 2 days now…

Also have the same problem.

I’ve followed the steps outlined above, but I am also stuck on #8 (attach to process not listing my device).

I’ve verified that all other steps have been successful (adb connection over tcp, displaying logcat over tcp, multicast enabled, development build + script debugging checked, etc.).

Hi,
Also have the same problem.
I completed all the steps but it still does not work.

On a forum, I read that android block multicast over wifi. I could not verify the information, is it true ?
it would explain the problems we have on some devices !

Mac OSX El Capitan
Unity 5.3.1 Patch 5.3.1p1
Monodevelop 5.9.6
Android device LG G4
Last update from Android Sdk

Can someone from Unity please chime in here? It’s been 10 months without a solution.

Not sure if this’ll help for y’all, but here are the steps I took to get my PC → Android setup working:

First off, if adb devices shows that your device over the network is unauthorized or something, then you may need to regenerate your adbkey file (link here: http://forum.xda-developers.com/verizon-lg-g3/help/unable-to-access-adb-t2830087). Presumably though, if you’re reading this thread you’ve been able to get through the first 7 steps; just thought I would mention it as this was an issue for me.

Once this was all sorted I could connect my device, push the game, even (I think) attach the profiler but I couldn’t find the device in the Attach to Process listing in Visual Studio or MonoDevelop. The reason for this I believe is because of what the last line on the man page mentions (link: http://docs.unity3d.com/Manual/AttachingMonoDevelopDebuggerToAnAndroidDevice.html):

This is something that is enabled & disabled in the router, and (in my case where I don’t have access to the router in my apartment) wasn’t something I could change. But, I was eventually able to attach the debugger to the device in VS2013 by manually inputting the IP address and the correct port (which WASN’T 5555, but 56216 or something like that. It was also different from the port the my Editor instance was using). This leads me to believe that the device was broadcasting its availability, but my PC wasn’t able to listen for it as multicasting was disabled.

So in my case I had to create an ad-hoc network hosted by the wireless NIC on my laptop that my device would connect to (link: Create Ad Hoc WiFi Hotspot In Windows 10, Here's How | Redmond Pie). Then I could see the AndroidPlayer in the Attach to Process window for both VS2013 and MonoDevelop.

1 Like

I have the same problem and finally got it work (I’m using iMac)
My android device connect to Internet via Internet sharing, so just turning on multicast on that interface.
Run the following command in terminal.
sudo route add -net 225.0.0.222/32 -interface bridge100
(bridge100 is your interface which internet sharing using)
And you should found android player in “Attach to Process” window.

2 Likes

Just a little addition that worked for me. Multicast was enabled but didn’t routed messages between cable and wifi. When I ran both devices over wifi it worked for me.

Guys,

I just managed to get the debugger attached to the app running on Android and it works great.

All I had to do was to close the Unity editor. For some unknown reason it was interfering with the listing of the device in the “Attach to process” window in MonoDevelop.

I hope this helps!

Manuel

I have the same problem and finally solve it
In my case,the modification of firewall get my PC to Android setup working.
I hope this helps!

I solved this problem by using VS 2017 instead of 2015.

Allowing Monodevelop through Windows Firewall worked for me.

I had to spend some time debugging an android device this week, here’s how i got mine going:
https://answers.unity.com/questions/1145960/attach-to-process-never-shows-my-device.html?childToView=1447046#answer-1447046

I’ve been having similar problems across two machines, and have managed to solve my problems with the help of info on this thread plus a bit.

The first problem I hit was that even when using USB debugging both target device and Unity Editor machine have to be on the same subnet. For me this meant both attached to the same wifi hotspot as their primary network connection.

Secondly, the router needs to support the right features / be configured correctly. Luckily for me I have two routers in my office and I had to connect both devices to the wifi on the second router (either both 5G or both 2.4G - didn’t work if they weren’t on the same). I suspect this is due to the multicast issue referenced in John Fallon’s post.

I used adb tcpip 5555, I did not need to connect via wifi with adb connect .

I had to make sure my PC had the wifi connection selected as a Private Network (click on startbar wifi symbol and click properties).

Finally I had to disable my firewall for private networks. Once I’d done this Visual Studio 2017 listed the AndroidPlayer (Debug → Attach Unity Debugger) and could connect to it. The strange thing was that I could then re-enable firewall for a while and it continued to work (even past a restart of Visual Studio) but then it failed again. Clearly some port needs to be opened.

1 Like