5

First of all, I'm positive that I've followed all steps in the Attaching MonoDevelop Debugger To An Android Device guide correctly (most importantly: having "Development Build" and "Script Debugging" enabled in the Build Settings).

When building & running a Unity Android app, however, my device (Samsung Galaxy S5, Android 6.0.1) just doesn't show up as a possible debug target in neither MonoDevelop, nor Visual Studio. For instance in Visual Studio, after clicking on Debug -> Attach Unity Debugger, in the "Select Unity Instance" window that opens I only see the Unity3d editor (Machine: local machine, Type: Editor). Debugging a Unity project that is run in the Unity Editor works fine, only debugging a project run on the physical android device doesn't work. It's the same for MonoDevelop.

I see the device as connected and online when doing

adb devices

I can also call adb shell commands (such as ls) on that device via command line. When I open Android Studio, I also see the device as a target for Logcat and even the just mentioned Unity Android app as a debuggable process (and when selecting it, all the correct logs that are expected from the running app).

I think it's safe to rule out a fault on the debugger side, because I tried

  • two different developer machines (both Windows 10 with current updates and without firewalls),
  • two different networks (home & university)
  • MonoDevelop, Visual Studio Community 2015, Visual Studio Professional 2017 RC (with respective Tools for Unity),
  • re-installing Unity3d,
  • different Unity3d projects (standard example project as well as own minimal example consisting of just a Text and a Button),
  • manually adding android:debuggable="true" to the project's AndroidManifest and
  • in Visual Studio manually connecting the debugger to the device via deviceip:5555 (in the "Select Unity Instance" Window -> Input IP).

On the device, I tried to

  • turning the phone off and on again,
  • turn USB debugging off & on,
  • selecting the Unity App as the "debug app" (in Developer options) and enabling/disabling "Wait for debugger" (also Developer options),
  • connecting the device via USB cable or via adb connect deviceip:5555 and
  • rooting the phone.

I don't know what else to try. I'm pretty sure it's something on the device. It has worked before, however I don't know what changed since then. Any tips are appreciated.

EDIT

Ok so I got some progress. When I examined the logcat output from the app, I found lines such as

Waiting for connection from host on [192.168.2.110:55416]...

(.2.110 being the IP of the device) So I manually entered that IP & Port in Visual Studio in "Select Unity Instance" Window -> Input IP and right after that, the logcat read

PlayerConnection accepted from [192.168.2.115] handle:0x1c

(.2.115 being my developer machine) So the connection is there. Visual Studio just doesn't "recognize" (?) it and doesn't switch to debugging mode so it can stop at breakpoints. Does anyone have an idea how I can force it to do so?

3
  • Did you solve it? I have the same problem , PlayerConnection is accepted but visual studio doesn't swith to debug mode
    – D4rWiNS
    Aug 24, 2017 at 10:32
  • Not really, I only found the workaround that I described in one of the answers.
    – Tom Ladek
    Aug 25, 2017 at 9:30
  • See checklist stackoverflow.com/questions/60272891/… Jun 29, 2021 at 14:32

2 Answers 2

6

Well, not really an answer but I've found a way to debug it after all. Amidst all the logcat output, I've also found that line:

Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,defer=y,address=0.0.0.0:56785

Taking that port (and the actual device IP) and entering it in Visual Studio in the "Select Unity Instance" Window -> Input IP, the debugger finally connected.

The problem is, that port gets changed every time the app is run so in order to debug it, I'll always have to look it up. Also (that may be a different issue altogether), the output of Debug.Log or Console.WriteLine isn't caught by the debugger. The only way to read the log for now is in AndroidStudio.

So yeah, the question still stands, how come the device doesn't show up as AndroidPlayer in the Select Unity Instance Window in Visual Studio (or according place in MonoDevelop)?

2
  • 1
    you, sir, are a hero. Apr 6, 2017 at 11:15
  • For me (Unity 2019.2.21f1), the relevant logcat line was: D Unity : Starting managed debugger on port 56176
    – Felix
    Nov 9, 2020 at 15:10
1

It does show up if your Android device is connected to wifi. When the app starts playing, you can see it in the "Select Unity Instance" box and then you can select it.

2
  • Unfortunately no. In my case it didn't matter whether the device was connected via USB cable (Wifi on or off) or over Wifi via adb.
    – Tom Ladek
    May 6, 2017 at 8:09
  • Well, I afraid to say that it doesn't always work. But I did succeed a few times. So I just thought it might help you too.
    – Jeni Lisa
    May 7, 2017 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.