the android quit when I first run the APP in .net MAUI?

mc 7,231 Reputation points
2026-08-03T12:39:00.46+00:00

I am using .net MAUI 9.0 and when I first debug the APP will crash/quit in android.

and then I debug it runs well. and when I uninstall it and then debug again it will crash/quit again.

how to find the error of it? there is no exception

I run it on my mobile not emulator.

Developer technologies | .NET | .NET Multi-platform App UI

Answer accepted by question author

Tony Thach (WICLOUD CORPORATION) 240 Reputation points Microsoft External Staff Moderator
2026-08-04T05:04:08.8066667+00:00

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:

  1. Uninstall the application from the device.
  2. Start log collection.
  3. Deploy and launch the application again.
  4. 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. Android SDK platform-Tools

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: enter image description here

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. 

Was this answer helpful?

2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. AI answer

    2026-08-03T12:39:22.9+00:00

    Use the first-run deployment path as the main clue.

    On the first run in an Android emulator, .NET MAUI installs the shared runtime for the targeted API level before deploying the app. That first deployment can behave differently from later runs because the runtime is not yet present. If the emulator is unstable or not fully connected through ADB, the app can quit on that first launch and then work on later launches.

    To find the failure point, use this troubleshooting path:

    1. Start the emulator manually
      • Open Android Device Manager.
      • Start the virtual device directly and wait until it is fully booted.
      • Then run the app again from Visual Studio.
    2. Verify ADB can see the emulator
      • Open a command prompt.
      • Go to the folder containing adb.
      • Run:
             adb devices
        
      • Expected result: the emulator appears in the attached devices list, for example emulator-5554 device.
      • If it does not appear, apply Android SDK updates and try launching the emulator again.
    3. Launch the emulator from the command line for more detail
      • Start the emulator from the command line instead of Visual Studio so its output is visible.
      • This helps expose emulator-side startup problems that may not surface as a managed exception.
    4. Check Device Manager logs
      • Review the DeviceManager.log files under: %userprofile%\AppData\Local\Xamarin\Logs\16.0
      • These logs are often useful for diagnosing emulator startup and deployment issues.
    5. Recreate the emulator if the app shows “waiting for debugger” or quits only on first launch
      • Restart Visual Studio.
      • Delete the emulator and create it again.
      • This is a documented workaround when the emulator has an internal problem and the debugger cannot attach correctly.
    6. Keep the emulator running between sessions
      • After the first successful run, leave the emulator running.
      • Later debug sessions are faster because the .NET MAUI shared runtime is already installed.
      • If the device is restarted, the runtime is redeployed.
    7. If deploying to a physical device, test there as well
      • Plug in the device.
      • Select it as the debug target.
      • Run the app.
      • If the issue only happens on the emulator, that isolates the problem to the emulator environment rather than the app itself.

    If there is no exception in the app, the most likely place to find evidence is the emulator/ADB side rather than managed exception output.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

    1 person found this answer helpful.

Your answer

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