How to get diagnostics / trace or from a MAUI Android app that is crashing but no clear FATAL exception or clue

Matthew Waring 0 Reputation points
2024-09-12T11:49:32.25+00:00

Hi,

I have an app that is crashing in MAUI Android, but when looking at logcat or in the console etc, I cannot see any FATAL Exception or other native information to give me a clue to work out what to do next?

Could someone be so kind to give me ideas on how to get detailed diagnostics (using Rider at the moment on MAC), I think it used to be -v -v -v etc.

Or any other suggestions / links on diagnosing Android NET would be helpful, thank you.

Best
Matt

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,489 questions
{count} votes

1 answer

Sort by: Most helpful
  1. youzeliang 735 Reputation points
    2024-09-18T10:19:53.22+00:00

    To get more detailed diagnostics and traces from your .NET MAUI Android app that's crashing without a clear exception, you can use a few approaches:

    1. Logcat with Verbose Logging

    You can use adb logcat with verbose logging to capture more detailed logs, which could reveal subtle issues that aren't showing up in default logs.

    Run this command in your terminal:

    adb logcat *:V
    

    The *:V sets the verbosity level to the maximum, showing everything from verbose logging to errors. This can help you spot warnings or issues that don't show up as fatal exceptions.

    1. Enable Debugging Logs in .NET MAUI

    To get more diagnostics from the .NET side of your MAUI app, you can enable detailed tracing by setting environment variables in your app. Add this to your MainActivity.cs:

    AndroidEnvironment.UnhandledExceptionRaiser += (sender, args) =>
    {
        System.Diagnostics.Debug.WriteLine("Unhandled Exception: " + args.Exception);
        args.Handled = true; // Prevent app from crashing
    };
    
    

    This logs detailed .NET runtime information and can help reveal background issues with threads, assemblies, or other components.

    1. Use Android Profiler

    Rider integrates with Android Profiler (via Android Studio tools) to monitor CPU, memory, and network activity. This can help identify performance bottlenecks or resource leaks that might be causing the crash.

    To use it:

    • Launch your app and open Android Profiler via View > Tool Windows > Profiler.
    • Start profiling your app and look for memory spikes, CPU overloads, or network failures that could cause a crash.

    If my answer is helpful to you, you can accept it. Thank you.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.