Debug Instant Close Of Xamarin App Xamarin

Nov 7th, 2016 - written by Kimserey with .

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:

1
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:

1
<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:

1
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!

Designed, built and maintained by Kimserey Lam.