MAUI Template Project Crash Issue

MAUI Template Project Crash Issue

When using the MAUI framework, I encountered the issue that the newly created template application would crash directly on startup. I eventually solved this crash problem and share this experience.

Last updated 6/18/2022 2:57 PM
gui.h
11 min read
Category
MAUI
Tags
.NET MAUI

When MAUI was first released, I had created several template projects to try it out and didn't encounter any issues. Recently, I needed to develop an application for cash registers (Android system) used in the catering industry. These cash registers generally have low specs, and the system version and performance are definitely not as good as the phones we use. During technology selection, I first thought of MAUI, with alternatives being Flutter and React Native. All are cross-platform application frameworks maintained by big companies. When using the MAUI framework, I encountered a problem where the newly created template app would crash directly upon launch. I eventually solved this crash issue, so I'm sharing this experience.

Creating the Project

Demonstrating the project creation process, all steps follow the IDE defaults without any modifications.

Creating a New MAUI Template Project

Create a new MAUI template project in VS, as shown below:

The project name defaults to MauiApp1:

Connecting the Device

  • Connect the target Android device via USB.
  • Enable developer mode on the target device, then enable USB debugging (search Baidu Bing/Google yourself).
  • Switch the USB debugging mode on the phone. Generally, options like "Charge only", "File transfer", etc. appear. Simply toggle through the various options until VS lists your device.

Debugging the Project

After completing the device connection in the previous step, start the project in debug mode directly:

Wait a moment, you can see the app has been installed on the device. It should have been launched automatically, but after waiting a long time, nothing happened. The VS output window also stopped showing new content:

Manually tap the installed MauiApp1 app on the device. I just saw the splash screen with a large .NET logo, and then a "Maui1 has stopped running" message appeared:

Solving the Crash Issue

I have previously developed native Android apps using Android Studio. Typically, such issues produce error output in the IDE, and you can find the cause of the crash through the error information.

Reflecting on this issue, I didn't know where to check the logs. How could I find the cause of the crash? If only VS could show detailed logs like Android Studio. I don't know if there is a place to view detailed debug logs yet. I chose a more universal troubleshooting method: the adb tool.

I won't go into adb here; if readers have questions, search Baidu Bing/Google yourself. You just need to know it's a powerful tool for debugging Android apps.

The following steps require you to add the adb directory to the environment variable PATH so that the adb command can be used globally.

Common Commands

Use adb to list all app package names installed on the phone:

adb shell pm list packages

List all system-app package names:

adb shell pm list packages -s

List all third-party app package names (excluding system apps):

adb shell pm list packages -3

Search for a keyword that might be in a package name:

adb shell dumpsys activity | findstr mFocusedActivity

Clear app data and cache:

adb shell pm clear app_package_name

View logs:

adb logcat
  • V: Verbose (lowest priority)
  • D: Debug
  • I: Info
  • W: Warning
  • E: Error
  • F: Fatal
  • S: Silent (highest priority, never output)

Finding the Logs We Want

Confirm that adb recognizes your device:

$ adb devices
List of devices attached
1234567890ABCDEF        device

Find our package name:

$ adb shell pm list packages -3
....
package:com.landi.print.service
package:com.companyname.mauiapp1
....

The package name is: com.companyname.mauiapp1

  • Using logcat

Running adb logcat directly shows all device logs, which can interfere with our troubleshooting. We only need to see logs for package:com.companyname.mauiapp1. We can use grep to filter. The Windows command prompt does not support this natively, but I used GitBash's shell command line tool, which supports this feature.

adb logcat | grep com.companyname.mauiapp1

This will output only the logs for mauiapp1.

After executing the above command, click the mauiapp1 app icon to launch it. We get all logs from app launch to crash as follows:

06-16 10:21:11.953  1424  1424 D Launcher2.2.10: flow not clicked com.companyname.mauiapp1crc64e632a077a20c694c.MainActivity
06-16 10:21:11.953  1424  1424 D Launcher2.2.10: flow click desktop com.companyname.mauiapp1crc64e632a077a20c694c.MainActivity
06-16 10:21:11.953   424   466 I ActivityManager: START u0 {act=android.intent.action.MAIN flg=0x10200000 cmp=com.companyname.mauiapp1/crc64e632a077a20c694c.MainActivity} from uid 10072
06-16 10:21:11.958   424   466 E ActivityManager: getPackageFerformanceMode--ComponentInfo{com.companyname.mauiapp1/crc64e632a077a20c694c.MainActivity}----com.companyname.mauiapp1
06-16 10:21:11.967   424  1456 E ActivityManager: getPackageFerformanceMode--ComponentInfo{com.companyname.mauiapp1/crc64e632a077a20c694c.MainActivity}----com.companyname.mauiapp1
06-16 10:21:11.987   424  1456 I ActivityManager: Start proc 19415:com.companyname.mauiapp1/u0a97 for activity com.companyname.mauiapp1/crc64e632a077a20c694c.MainActivity
06-16 10:21:12.173 19415 19415 D debug-app-helper: Checking if libmonodroid was unpacked to /data/app/com.companyname.mauiapp1-Wpq5srmqUiNM5498jRmH8Q==/lib/arm/libmonodroid.so
06-16 10:21:12.173 19415 19415 D debug-app-helper: Native libs extracted to /data/app/com.companyname.mauiapp1-Wpq5srmqUiNM5498jRmH8Q==/lib/arm, assuming application/android:extractNativeLibs == true
06-16 10:21:12.173 19415 19415 D debug-app-helper: Added filesystem DSO lookup location: /data/app/com.companyname.mauiapp1-Wpq5srmqUiNM5498jRmH8Q==/lib/arm
06-16 10:21:12.173 19415 19415 W debug-app-helper: Using runtime path: /data/app/com.companyname.mauiapp1-Wpq5srmqUiNM5498jRmH8Q==/lib/arm
06-16 10:21:12.173 19415 19415 W debug-app-helper: checking directory: `/data/user/0/com.companyname.mauiapp1/files/.__override__/lib`
06-16 10:21:12.173 19415 19415 W debug-app-helper: directory does not exist: `/data/user/0/com.companyname.mauiapp1/files/.__override__/lib`
06-16 10:21:12.173 19415 19415 W debug-app-helper: Checking whether Mono runtime exists at: /data/user/0/com.companyname.mauiapp1/files/.__override__/libmonosgen-2.0.so
06-16 10:21:12.173 19415 19415 W debug-app-helper: Checking whether Mono runtime exists at: /data/app/com.companyname.mauiapp1-Wpq5srmqUiNM5498jRmH8Q==/lib/arm/libmonosgen-2.0.so
06-16 10:21:12.173 19415 19415 I debug-app-helper: Mono runtime found at: /data/app/com.companyname.mauiapp1-Wpq5srmqUiNM5498jRmH8Q==/lib/arm/libmonosgen-2.0.so
06-16 10:21:12.192 19415 19415 W monodroid: Creating public update directory: `/data/user/0/com.companyname.mauiapp1/files/.__override__`
06-16 10:21:12.198 19415 19415 F monodroid: No assemblies found in '/data/user/0/com.companyname.mauiapp1/files/.__override__' or '<unavailable>'. Assuming this is part of Fast Deployment. Exiting...
06-16 10:21:12.275 19433 19433 F DEBUG   : pid: 19415, tid: 19415, name: nyname.mauiapp1  >>> com.companyname.mauiapp1 <<<
06-16 10:21:12.284 19433 19433 F DEBUG   : Abort message: 'No assemblies found in '/data/user/0/com.companyname.mauiapp1/files/.__override__' or '<unavailable>'. Assuming this is part of Fast Deployment. Exiting...'
06-16 10:21:12.288 19433 19433 F DEBUG   :     #01 pc 0001b08b  /data/app/com.companyname.mauiapp1-Wpq5srmqUiNM5498jRmH8Q==/lib/arm/libmonodroid.so (xamarin::android::internal::MonodroidRuntime::create_domain(_JNIEnv*, xamarin::android::jstring_array_wrapper&, bool, bool)+282)
06-16 10:21:12.288 19433 19433 F DEBUG   :     #02 pc 0001c08f  /data/app/com.companyname.mauiapp1-Wpq5srmqUiNM5498jRmH8Q==/lib/arm/libmonodroid.so (xamarin::android::internal::MonodroidRuntime::create_and_initialize_domain(_JNIEnv*, _jclass*, xamarin::android::jstring_array_wrapper&, xamarin::android::jstring_array_wrapper&, _jobjectArray*, xamarin::android::jstring_array_wrapper&, _jobject*, bool, bool, bool)+26)
06-16 10:21:12.288 19433 19433 F DEBUG   :     #03 pc 0001d2c5  /data/app/com.companyname.mauiapp1-Wpq5srmqUiNM5498jRmH8Q==/lib/arm/libmonodroid.so (xamarin::android::internal::MonodroidRuntime::Java_mono_android_Runtime_initInternal(_JNIEnv*, _jclass*, _jstring*, _jobjectArray*, _jstring*, _jobjectArray*, _jobject*, _jobjectArray*, int, unsigned char, unsigned char)+4020)
06-16 10:21:12.288 19433 19433 F DEBUG   :     #04 pc 0001d55f  /data/app/com.companyname.mauiapp1-Wpq5srmqUiNM5498jRmH8Q==/lib/arm/libmonodroid.so (Java_mono_android_Runtime_initInternal+50)
06-16 10:21:12.288 19433 19433 F DEBUG   :     #05 pc 0005282f  /data/app/com.companyname.mauiapp1-Wpq5srmqUiNM5498jRmH8Q==/oat/arm/base.odex (offset 0x2e000)
06-16 10:21:12.905   424 19434 W ActivityManager:   Force finishing activity com.companyname.mauiapp1/crc64e632a077a20c694c.MainActivity
06-16 10:21:12.916   424   451 I ActivityManager: Showing crash dialog for package com.companyname.mauiapp1 u0
06-16 10:21:12.976   424   877 I ActivityManager: Process com.companyname.mauiapp1 (pid 19415) has died: fore TOP

We only need to focus on log levels F and E:

The following error information indicates the reason for the crash:

06-16 10:21:12.198 19415 19415 F monodroid: No assemblies found in '/data/user/0/com.companyname.mauiapp1/files/.__override__' or '<unavailable>'. Assuming this is part of Fast Deployment. Exiting...
06-16 10:21:12.275 19433 19433 F DEBUG   : pid: 19415, tid: 19415, name: nyname.mauiapp1  >>> com.companyname.mauiapp1 <<<
06-16 10:21:12.284 19433 19433 F DEBUG   : Abort message: 'No assemblies found in '/data/user/0/com.companyname.mauiapp1/files/.__override__' or '<unavailable>'. Assuming this is part of Fast Deployment. Exiting...'

Next, we can apply one of the essential skills of a programmer: Baidu Google. It all depends on whether you can find the correct answer.

It seems the author found something. A similar case was found on StackOverflow: https://stackoverflow.com/questions/42336546/xamarin-android-application-crashed-after-clear-data-in-settings

If interested, dive deeper. The solution there for Xamarin was to turn off "Use Fast Deployment".

Modifying Project Configuration

After carefully checking the property configuration file, I found a setting very similar to turning off "Use Fast Deployment" as mentioned on StackOverflow. It should be it. Disable it and try starting the project in debug mode from VS again.

This time, after a slightly longer process, it also stopped at "Found device: 1234567890ABCDEF" and didn't proceed:

Manually open the app, but nothing happens.

Uninstall Mauiapp1 and Retry

Although the above change didn't work, I firmly believe this should be the correct approach. So let's uninstall the app and try again to eliminate interference.

After "Found device: 1234567890ABCDEF", the process no longer hangs. Then, the app is installed and automatically launched on my device, and it does not crash!

Keep Exploring

Related Reading

More Articles