Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android device doesn't show up as target of Unity3d debugging

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?

like image 893
Tom Ladek Avatar asked Feb 22 '17 13:02

Tom Ladek


1 Answers

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

like image 111
Tom Ladek Avatar answered Sep 27 '22 17:09

Tom Ladek