Xamarin构建应用在客户远程设备崩溃问题求助
Unable to find application Mono.Android.Platform.ApiLevel_24 or Xamarin.Android.Platform First, let's recap the crash context: You've enabled unknown source installs, the app runs fine on your dev/non-dev devices, but crashes immediately on a client's remote device with the following stack trace:
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! E/AndroidRuntime( 8048): at android.app.ActivityThread.installProvider(ActivityThread.java:5571) E/AndroidRuntime( 8048): at android.app.ActivityThread.installContentProviders(ActivityThread.java:5163) E/AndroidRuntime( 8048): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5103) E/AndroidRuntime( 8048): at android.app.ActivityThread.access$1600(ActivityThread.java:177) E/AndroidRuntime( 8048): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1510) E/AndroidRuntime( 8048): at android.os.Handler.dispatchMessage(Handler.java:102) E/AndroidRuntime( 8048): at android.os.Looper.loop(Looper.java:145) E/AndroidRuntime( 8048): at android.app.ActivityThread.main(ActivityThread.java:5951) E/AndroidRuntime( 8048): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime( 8048): at java.lang.reflect.Method.invoke(Method.java:372) E/AndroidRuntime( 8048): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388) E/AndroidRuntime( 8048): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183) E/AndroidRuntime( 8048): Caused by: java.lang.RuntimeException: Unable to find application Mono.Android.Platform.ApiLevel_24 or Xamarin.Android.Platform! E/AndroidRuntime( 8048): at mono.MonoRuntimeProvider.attachInfo(MonoRuntimeProvider.java:38) E/AndroidRuntime( 8048): at android.app.ActivityThread.installProvider(ActivityThread.java:5568) E/AndroidRuntime( 8048): ... 11 more E/AndroidRuntime( 8048): Caused by: android.content.pm.PackageManager$NameNotFoundException: Xamarin.Android.Platform E/AndroidRuntime( 8048): at android.app.ApplicationPackageManager.getApplicationInfo(ApplicationPackageManager.java:305) E/AndroidRuntime( 8048): at mono.MonoRuntimeProvider.attachInfo(MonoRuntimeProvider.java:32) E/AndroidRuntime( 8048): ... 12 more
This error almost always ties to how the app is packaged (your dev devices have Xamarin's runtime dependencies pre-installed, but client devices don't). Here are the step-by-step fixes you should try:
Switch to Release Mode with Independent Packaging
Your dev environment uses the Xamarin Shared Runtime to speed up deployments, but client devices don't have this runtime installed. In Visual Studio:- Switch your build configuration to Release.
- Right-click your Android project → Properties → Android Options.
- Under the Packaging tab, uncheck Use Shared Runtime (this ensures all Mono/Xamarin dependencies are bundled directly into your APK).
- For better compatibility, enable Generate one package (.apk) if targeting multiple architectures, or select the specific architecture matching the client's device.
Verify API Level Consistency
The log mentionsApiLevel_24, so double-check:- In Android project properties, ensure Target Framework, Compile Using Android Version, and Minimum Android Version are set consistently (e.g., if targeting API 24, make sure the min version isn't higher than the client's device Android version).
- Confirm you haven't accidentally mixed API levels in your project references.
Clean and Rebuild Your Project
Corrupted build artifacts often cause this issue:- Go to Build → Clean Solution.
- Manually delete the
binandobjfolders from your Android project directory. - Rebuild the solution and re-package the APK.
Disable Fast Deployment
Fast Deployment is a dev-only feature that skips bundling some files. Disable it in Release mode:- In Android project properties → Android Options → Debugging.
- Uncheck Enable Fast Deployment.
Validate APK Integrity
Ensure the APK you sent to the client isn't corrupted:- Re-sign the APK with your release keystore (if you haven't already).
- Have the client re-download/receive the APK and reinstall it, making sure they've fully uninstalled any previous versions first.
Check Client Device Android Version
If the client's device is running an Android version lower than API 24, adjust your project's Minimum Android Version to match (or lower) that version, then rebuild and re-deploy.
These steps should resolve the missing runtime provider issue in most cases.
内容的提问来源于stack exchange,提问作者Sai Kishore

