If you are just starting out with Xamarin development, you may not have delved through all the bits and pieces of the toolset, particularly in the debugging space.
I was reminded earlier today of the joy of discovering the sheer usefulness of this little icon in Visual Studio:
At the time, I had just started out in Xamarin Forms and was stumped by my app crashing whenever I ran it on a physical device.
The app was fairly simple. I was using one of James Montemagno’s excellent plugins to access the camera, take a picture and upload it to a web service. Every time I ran the app on a real device it just exited. When I ran it on the emulator it was fine. I wasn’t really accustomed to Android’s logs at the time, so, although the answer (permissions!) seems obvious now, it took a while to track down.
I’ll point my beginner readers towards the Device Log and the wealth of information you can discover.
The magic button
When you click on the magic toolbar button, the Android device log will appear in a dockable Visual Studio window.
Choose a device from the drop-down – in this example I have a physical Google Pixel plugged into the PC. If your device is anything like a typical Android phone, you will get an avalanche of events start to scroll past you at high speed. Luckily, hovering over the column headers reveals a handy filter that lets you focus on only the events you want to see.
There is also a Search box for free text searching:
I find it useful to clear the log, launch the app then immediately pause the log after the crash. I then do a Search for ‘Exception’ and scan through the log entries to find my app or activity name.
Here’s a typical permissions exception. In this case the app is asking for the users location without being granted the necessary permissions:
The sheer amount of information available in this log is quite amazing.
Take a few minutes and run some apps, watch the events go past and take a look at the interesting ones. It can be quite an insight into what your device is up to and often an invaluable debugging tool.