A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Hello @mc ,
Thanks for your question.
Based on the behavior you described, I would focus on the first-install / first-launch scenario as the primary clue.
Since the application crashes only after a fresh install and then runs normally on subsequent launches, I recommend capturing Android runtime logs rather than relying solely on the debugger output.
Startup exceptions do not always appear in the IDE, especially when they occur during Android initialization.
You can start with:
adb logcat -c
adb logcat
Then:
- Uninstall the application from the device.
- Start log collection.
- Deploy and launch the application again.
- Reproduce the crash.
However, adb logcat can produce a very large amount of output, making it difficult to identify the actual issue. You can narrow the results using the following commands.
Show only errors:
adb logcat *:E
Show Android runtime errors and fatal exceptions only:
adb logcat AndroidRuntime:E *:S
Filter for your application process only
Find the PID:
adb shell pidof YOUR_APP_ID
Note: You can find your Application ID in </ApplicationId> .csproj file.
Example output: 12345, then filter logs by PID:
adb logcat --pid=12345
This approach works regardless of whether you're using Visual Studio, VS code, Rider, or the .NET CLI.
I also tested this approach locally by reproducing a similar startup crash scenario in a .NET MAUI application running on Android. The log filtering commands above successfully captured the exception details, which confirms that they are useful for diagnosing startup issues.
Note
Make sure that Android SDK platform-Tools is installed and the folder containing adb.exe has been added to your system PATH environment variable.
You can remove the application either manually from the device or by using:
adb uninstall YOUR_APP_ID
To verify that Logcat can capture startup exceptions correctly, I added the following temporary TEST CODE in App.xaml.cs:
#if DEBUG
if (DeviceInfo.Platform == DevicePlatform.Android)
{
bool firstRun = Preferences.Default.Get("CrashTest_FirstRun", true);
if (firstRun)
{
Preferences.Default.Set("CrashTest_FirstRun", false);
throw new Exception("Intentional first-launch crash for testing");
}
}
#endif
Using:
adb logcat AndroidRuntime:E *:S
the resulting log clearly identified the exception:
The stack trace also pointed directly to the location where the exception was thrown, making it much easier to identify the root cause.
The Logcat steps above should make it much easier to identify startup exceptions that may not appear in the debugger output.
If my explanation and the information I provided were helpful, I would greatly appreciate it if you could follow the instruction here so others experiencing similar behavior can benefit from it as well.