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?