Forum Xamarin.Forms

Can't debug on android devices in visual studio

Since I have started with Xamarin I have had problems getting the android debugging to work.

Every time I deploy a Xamarin Forms (PCL) project to my phone (LG G Flex 2, Android 5.1 lollipop), the deploy succeeds, enters debug mode for about 6 or 7 seconds, then goes out of the debug mode without any errors and closes the app on my phone. The app is installed however and I can use it afterwards.

I have a laptop and a pc, both running Visual Studio 2015 update 2, both have the same problem with every project.
These problems only occur when debugging for Android, not for Windows or Windows Phone, (no idea about IOS).

The output tab (Debug) only shows:
Android application is debugging. Couldn't connect to logcat, GetProcessId returned: 0
That last line is only showed on my laptop and not on my pc.

The output from Xamarin Diagnostics :
[D:RunShellCommand]: LGH955833bfe56 getprop [D:RunShellCommand]: LGH955833bfe56 getprop [D:RunShellCommand]: LGH955833bfe56 date +%s [D:RunShellCommand]: LGH955833bfe56 setprop "debug.mono.extra" "debug=,timeout=1464533426,loglevel=0,server=y" [D:RunShellCommand]: LGH955833bfe56 am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "Project.Droid/md5ebb414a62e6ccdc1a237d6523954780b.MainActivity" [D:RunShellCommand]: LGH955833bfe56 ps [D:RunShellCommand]: LGH955833bfe56 am force-stop Project.Droid [D:RunShellCommand]: LGH955833bfe56 setprop "debug.mono.connect" ""

As you can see it forces the application to close for some reason, but i have no idea what's causing it.
On my pc the output is about the same except for 2 extra lines concerning the logcat.

Any idea on how to fix this?


  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    Are you using Xamarin.Forms or a Xamarin Android project? What the versions of XF / XA?

    Sometime back I had similar problem but reverse to your case. That is I could debug on my phone (Samsung GN4) but not on the VS Emulator. This is the thread which also indicates the solution I found.

  • I am using Xamarin.Forms both of my machines, but i even updated to on the one of them which didn't help, I have managed to debug on the Xamarin android player though, which works quite well.

    I have tried to change a couple of settings like the fast deployment, but all without success. I have tried using another phone before, but i will try this again next to be able to rule that out completely.

  • Other devices don't work either it seems

  • I was now able to debug on a device running Android 6.0, everything below that still doesn't seem to work

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    Did you do anything different to make it work?

  • No, it worked fine on my friends phone running Android 6.0, but my own 2 devices running android 5.1 still won't work. I am using the Xamarin Android Player to debug now since i have no other devices laying around.

    It might be interesting to note that both my devices are from LG, maybe it has something to do with their driver software.

  • TonyDTonyD USMember ✭✭✭

    I had this issue and fixed it with a Nexus phone last week.

    It had something to do with soft breakpoints VS hard breakpoints and I had to use adb to get it fixed.

    You can find adb under wherever the android platform-tools are installed.

    Then run:
    adb shell setprop debug.mono.soft_breakpoints 1
    OR adb shell setprop debug.mono.soft_breakpoints 0
    OR adb shell setprop debug.mono.env MONO_DEBUG=soft-breakpoints

    I tried all three in various combos but one of them ended up working.

  • I tried it, it didn't work for me, but it is sertainly an interesting answer, can you tell me where you got your information from?

    That way i can maybe try some more settings. Also, am i correct that there are only 2 combo's possible? one where the soft brakepoints is set to 0 and one where it is set to 1? i don't see how i can "reverse" or undo the last command.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @DiedeSeldeslachts I have an LG tablet at home. For some reason I have not loaded any of my projects on it. I will try it today evening and let you know.

  • MikeRowley403MikeRowley403 CAMember ✭✭✭

    You are likely running into this bug:

    Apparently there is a fix on its way.

  • @MikeRowley403 Thanks for the info, however it doesn't seem to be the same problem completely.

    This bug makes it difficult to test on phones with api 23+. I'd say the frequency is around ~66% of the time I attempt to debug my Forms application on a Nexus 6.

    I had no problem debugging on a OnePlus One running android 6.0 which is api 23 if i'm not mistaking. However, it fails 100% of the time on the other devices unfortunately.

    @ShantimohanElchuri Have you gotten around trying to debug on your LG device yet? I would be very interested to know the results of that test.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @DiedeSeldeslachts Sorry, I was not able to make my LG Tablet visible to VS. I am debugging the issue. My tablet is running Android 6.0. I have some updates in SDK Manager. Doing them. Will let you know.

  • @ShantimohanElchuri Have you installed the LG usb driver? You need it before VS can detect your device.
    Thank you for putting your time into this by the way.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @DiedeSeldeslachts At the it says to install the LG Bridge to install the LG usb driver fast. I did that. Still not seen by VS.

  • 1xo21xo2 NZMember ✭✭✭
    edited December 2018

    I have run into the same problem and this is what works for me.

    manually clean solution,
    switch between Courant debug mode to release mode.. save and then switch it back.

    manually uninstall your previous APK on the device.

    go to Android properties and select all properties that point to rebuild not from the start or any other manipulation on your code.

    properties > built > optimize code,
    properties > Android options >
    used share runtime and used Fast deployment

    cleaning solution and build manually (order dependency - so android last)

Sign In or Register to comment.