Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Attaching Monodevelop debugger to an Android device?

Discussion in 'Android' started by bluescrn, May 13, 2014.

  1. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    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:

    http://answers.unity3d.com/questions/456471/monodevelop-debugging-of-android-player-how-to-att.html

    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?)
     
  2. John Fallon

    John Fallon

    Unity Technologies

    Joined:
    Jul 1, 2014
    Posts:
    44
    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 <sdk>/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 http://developer.android.com/tools/help/adb.html)

    4) 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

    5) 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

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

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

    8) 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.
     
    Last edited: Dec 19, 2014
    mostwanted9192 and deLord like this.
  3. miketava

    miketava

    Joined:
    Jul 8, 2013
    Posts:
    2
    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?
     
  4. DaveA

    DaveA

    Joined:
    Apr 15, 2009
    Posts:
    310
    <Crickets>
    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.
     
    Last edited: Jun 10, 2015
  5. tdube

    tdube

    Joined:
    Aug 17, 2013
    Posts:
    1
    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).
     
  6. ju4nl

    ju4nl

    Joined:
    Sep 19, 2013
    Posts:
    9
    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?!!!
     
    Last edited: Jun 24, 2015
  7. mfreel

    mfreel

    Joined:
    Aug 22, 2013
    Posts:
    7
    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.
     
    BinaryBanana likes this.
  8. danieldourado_2

    danieldourado_2

    Joined:
    May 23, 2015
    Posts:
    2
    Still no answer for this? I am also stuck with the same problem for 2 days now...
     
  9. baboonus

    baboonus

    Joined:
    Apr 24, 2015
    Posts:
    1
    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.).
     
  10. PhilippeDu60

    PhilippeDu60

    Joined:
    Mar 5, 2013
    Posts:
    25
    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
     
  11. svenyonson

    svenyonson

    Joined:
    Nov 6, 2015
    Posts:
    1
    Can someone from Unity please chime in here? It's been 10 months without a solution.
     
  12. belbeeno

    belbeeno

    Joined:
    Aug 24, 2013
    Posts:
    1
    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: http://www.redmondpie.com/create-ad-hoc-wifi-hotspot-in-windows-10-heres-how/). Then I could see the AndroidPlayer in the Attach to Process window for both VS2013 and MonoDevelop.
     
    andreiagmu likes this.
  13. splash5

    splash5

    Joined:
    Nov 8, 2014
    Posts:
    13
    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.
     
    andreiagmu and tapiream like this.
  14. joey-squla

    joey-squla

    Joined:
    May 30, 2015
    Posts:
    16
    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.
     
    Last edited: Jun 20, 2016
  15. manuelpeirone

    manuelpeirone

    Joined:
    Mar 1, 2016
    Posts:
    1
    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
     
  16. sa645710118

    sa645710118

    Joined:
    Apr 23, 2017
    Posts:
    1
    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!
     
  17. deaconsyre

    deaconsyre

    Joined:
    May 10, 2017
    Posts:
    2
    I solved this problem by using VS 2017 instead of 2015.
     
  18. scheffield

    scheffield

    Joined:
    Aug 7, 2017
    Posts:
    2
    Allowing Monodevelop through Windows Firewall worked for me.
     
  19. naviln

    naviln

    Joined:
    Oct 18, 2016
    Posts:
    32
  20. jules_fpvr

    jules_fpvr

    Joined:
    Jan 8, 2016
    Posts:
    35
    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 <ip-address>.

    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.
     
    Last edited: Jan 15, 2018
    samelin_mipumi likes this.
  21. UriMitosis

    UriMitosis

    Joined:
    Dec 11, 2017
    Posts:
    6
    Same problem. It would be wonderful if someone from unity could respond here - it would seem to be a serious oversight that this is not documented in an FAQ somewhere. These are very easy problems to run into, and there are 17 different answers on this page. I will now try each of them in alphabetical order. Sigh.
     
  22. UriMitosis

    UriMitosis

    Joined:
    Dec 11, 2017
    Posts:
    6
    Found an answer!

    1) attach your device to your computer with a USB. You may have to disable your firewall
    2) start ADB in your command prompt/terminal. The comand for this is
    ```adb tcpip 5555```
    3) start logcat. The command is `adb logcat`. This will print all the ADB output to the terminal
    4) start the app on android.
    5) Now find IP and port associated with your device. The IP is the IP of your phone. To find the port, look for the line
    ```--debugger-agent=transport=dt_socket,embedding=1,defer=y,address=0.0.0.0:56052```
    in the logcat output.
    6) attach visual studio to this IP and port. to do this go to the menu in visual studio. click Debug > Attach Unity Debugger. Click "Input IP" (bottom left of the pop up window). Input the IP and port you found in the last step. It will take about 30 seconds to attach, but it should then hit any breakpoints you set.

    Note that the port will be different every time. Thank you [Stackoverflow][1]


    [1]: https://stackoverflow.com/questions...doesnt-show-up-as-target-of-unity3d-debugging
     
    zhuchun, andreiagmu and BinaryBanana like this.
  23. BinaryBanana

    BinaryBanana

    Joined:
    Mar 17, 2014
    Posts:
    81
    Thank you @UriMitosis , that is exactly my problem. I am on unity 2018.3, I am using phone and PC for which I was able to connect before with USB. Now it stopped working and I don't know why. The only way is to find that IP and exact port and attach manually to the device.

    I really hope Unity team can fix it for us.
     
  24. engilas

    engilas

    Joined:
    May 21, 2019
    Posts:
    1
    Im' trying to do the same with android emulator Bluestacks, but can't connect to the port found with logcat, because no one listen it
     
  25. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    229
    For me disabling
    autoconnect profiler
    fixed it