How to fix Xamarin Android app instantly closing with error after deployment

Xamarin.Android app instantly closing with error after deployment

Last week I had an issue suddenly after updating Xamarin.Android and downloading the latest Android sdk 24.

My application kept closing instantely after being deployed showing the following error:

Unfortunately, [App name] has stopped.

img

I looked online and all I found was answers which recommended to uninstall the app either through the Android settings or using adb uninstall <package name>, clean and rebuild but nothing did it. It was still crashing.

1. Scoping the issue

I wasn’t sure what was going on until I remembered that I could access the logs via adb logcat. After inspecting the logs, I saw the following error message:

AndroidRuntime: java.lang.RuntimeException: Unable to get provider mono.MonoRuntimeProvider: java.lang.RuntimeException: Unable to find application Mono.Android.Platform.ApiLevel_24 or Xamarin.Android.Platform!

It was that it couldn’t find ApiLevel_24 but my manifest was configured as followed:

<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="23" />

The problem was that my VM was running API 23, the app was configured to target API 23 but somehow, when the app ran it was looking for API 24 which caused it to crash.

Notes:

It’s always useful to be able to output the logs to a text file. If you want to do that, you can use the following command:

adb logcat -t 500 *:E > logs.txt

-t 500 would take the last 500 lines and *:E would filter the log with a priority of E: Error. Finally it will pipe it to a logs.txt.

2. Fixing the issue

The problem was in the csproj file.

AndroidUseLatestPlatformSdk was set to true which was forcing the app to look for the latest sdk and the latest sdk I installed was 24! After setting it to false all went well again.

You can also set it from right click on project > Options > General > Target framework > Select your framework.

menu

Conclusion

Remember to use adb logcat to check the issue and make sure you are targeting the correct version of Android. Hope this post was helpful for you! As usual if you have any comments leave it here or hit me on Twitter @Kimserey_Lam.

Other post you will like!

Comments

  1. Kimserey, thank you so much for taking the time to blog this. I was having the same issue recently after upgrading my SDK's.

    ReplyDelete
  2. Thanks a lot, this happend at my work and no one has idea of whats on going on.

    ReplyDelete

Post a Comment

Popular posts from this blog

Absolute layout and relative layout Xamarin forms

Build an Accordion view in Xamarin.Forms

Use Font Awesome from Xamarin.Android for your Xamarin.Forms project