【问题标题】:MvxException in Release Mode for AndroidAndroid 发布模式下的 MvxException
【发布时间】:2023-03-15 11:55:02
【问题描述】:

我有我自己无法解决的问题。我无法在发布模式下运行我的 android api,它在加载 System.Web.Service.dll 库时停止,然后我得到了 MvxException,继续后我得到了第二个 MvxExcetpion(我从调试模式猜测它即将关闭应用程序)。

我正在使用 MvvmCross - 我在 WindowsPhone7 中的应用程序运行良好,但在 Mono for Android 中我遇到了问题。

这是我的输出日志:

- 08-15 17:06:13.242 I/monodroid-gc( 1873): environment supports jni NewWeakGlobalRef
- 08-15 17:06:13.292 W/monodroid-gc( 1873): GREF GC Threshold: 1800
- Loaded assembly: SmartWash.UI.dll
- Loaded assembly: SmartWash.Core.dll
- Loaded assembly: Cirrious.MvvmCross.Android.dll
- Loaded assembly: Newtonsoft.Json.MonoDroid.dll
- Loaded assembly: Cirrious.MvvmCross.Binding.Android.dll
- Loaded assembly: Mono.Android.dll [External]
- Loaded assembly: System.Core.dll [External]
- Loaded assembly: System.dll [External]
- Loaded assembly: MonoDroidConstructors [External]
- Loaded assembly: System.Xml.dll [External]
- Loaded assembly: System.Web.Services.dll [External]
- Unhandled Exception:

- Cirrious.MvvmCross.Exceptions.MvxException: 
- 08-15 17:06:31.972 I/MonoDroid( 1873): UNHANDLED EXCEPTION: Cirrious.MvvmCross.Exceptions.MvxException: No Service Factory Constructor included in Assembly!
- 08-15 17:06:31.972 I/MonoDroid( 1873): at Cirrious.MvvmCross.Platform.MvxServiceProviderSetup.Initialize (System.Type,Cirrious.MvvmCross.Interfaces.IoC.IMvxIoCProvider) <IL 0x0002b, 0x001a8>
- 08-15 17:06:31.972 I/MonoDroid( 1873): at Cirrious.MvvmCross.Platform.MvxServiceProviderSetup.Initialize (Cirrious.MvvmCross.Interfaces.IoC.IMvxIoCProvider) <IL 0x00008, 0x0007b>
- 08-15 17:06:31.972 I/MonoDroid( 1873): at Cirrious.MvvmCross.IoC.MvxOpenNetCfServiceProviderSetup.Initialize () <IL 0x00007, 0x0008b>
- 08-15 17:06:31.972 I/MonoDroid( 1873): at Cirrious.MvvmCross.Platform.MvxBaseSetup.InitializeIoC () <IL 0x00000, 0x00043>
- 08-15 17:06:31.972 I/MonoDroid( 1873): at Cirrious.MvvmCross.Platform.MvxBaseSetup.InitializePrimary () <IL 0x00041, 0x001d7>
- 08-15 17:06:31.972 I/MonoDroid( 1873): at Cirrious.MvvmCross.Android.Views.MvxBaseSplashScreenActivity.OnCreate (Android.OS.Bundle) <IL 0x00036, 0x0018b>
- 08-15 17:06:31.972 I/MonoDroid( 1873): at SmartWash.UI.SplashScreenActivity.OnCreate (Android.OS.Bundle) <IL 0x00002, 0x0004f>
- 08-15 17:06:31.972 I/MonoDroid( 1873): at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.3-branch/410a5aba/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:1490
- 08-15 17:06:31.972 I/MonoDroid( 1873): at (wrapper dynamic-method) object.891313b6-5c12-4624-844c-14d43e535064 (intptr,intptr,intptr) <IL 0x00012, 0x00033>
- Unhandled Exception:

- Cirrious.MvvmCross.Exceptions.MvxException: 

我这几天一直在寻找解决方案,现在我太累了,无法自己解决。任何建议都非常受欢迎!

更新: 在链接“仅限 SDK”中添加 LinkerIncludePlease.cs 类后,我遇到了另一个我找不到的 NullReference 问题。

这是我的输出:

- 08-16 10:08:27.922 I/mono    ( 2334):   at Cirrious.MvvmCross.Android.ExtensionMethods.MvxAndroidActivityExtensionMethods.OnViewCreate<TViewModel> (Cirrious.MvvmCross.Android.Interfaces.IMvxAndroidView`1<TViewModel>) <IL 0x00043, 0x00243>
- 08-16 10:08:27.922 I/mono    ( 2334):   at Cirrious.MvvmCross.Android.Views.MvxTabActivityView`1.OnCreate (Android.OS.Bundle) <IL 0x00008, 0x00093>
- 08-16 10:08:27.922 I/mono    ( 2334):   at Cirrious.MvvmCross.Binding.Android.Views.MvxBindingTabActivityView`1.OnCreate (Android.OS.Bundle) <IL 0x00008, 0x00077>
In mgmain JNI_OnLoad
- 08-16 10:08:27.922 I/mono    ( 2334):   at Sm08-16 10:08:27.922 I/mono    ( 2334):   at SmartWash.UI.Views.BaseTabbedView`1.OnCreate (Android.OS.Bundle) <IL 0x0000a, 0x00083>
- 08-16 10:08:27.932 I/mono    ( 2334):   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <IL 0x00012, 0x000ef>
- 08-16 10:08:27.942 I/mono    ( 2334):   at (wrapper dynamic-method) object.dc29b95c-fdca-49d9-bdbc-e51d024c54c9 (intptr,intptr,intptr) <IL 0x00012, 0x00033>
08-16 10:08:27.942 I/mono    ( 2334):   at (wrapper native-to-managed) object.dc29b95c-fdca-49d9-bdbc-e51d024c54c9 (intptr,intptr,intptr) <IL 0x0001f, 0xffffffff>
- Unhandled Exception:

- System.NullReferenceException: 

- 08-16 10:08:59.102 I/MonoDroid( 2334): UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
- 08-16 10:08:59.102 I/MonoDroid( 2334): at (wrapper delegate-invoke) <Module>.invoke_intptr__this___intptr_intptr_intptr_JValue[] (intptr,intptr,intptr,Android.Runtime.JValue[]) <IL 0x0005d, 0x0011f>
- 08-16 10:08:59.102 I/MonoDroid( 2334): at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue[]) <IL 0x00012, 0x000a7>

【问题讨论】:

    标签: android xamarin.android mvvmcross


    【解决方案1】:

    这只是发布模式的事实,加上这是一个缺失类的事实,这表明这可能是一个 monodroid 链接问题 - monodroid 链接器剥离了太多类。

    解决此问题的最简单方法是将 monodroid 链接设置更改为“仅限 SDK”。

    更高级的解决方法是在主项目中包含对反射加载类的引用。一些 mvx 示例包含此机制的示例 - 查找名为 LinkerPleaseInclude.cs(或类似文件)的文件

    【讨论】:

    • 非常感谢您的帮助。好吧,我添加了 LinkerPleaseInclude.cs 类并且它有效!但仅在“仅 SDK”链接中。在“SDK 和用户大会”上,我遇到了同样的问题。这些选项之间有很大差异吗?第二个问题是,在“仅 SDK”链接中,我有登录活动,登录后我应该使用选项卡打开我的 MainMenu 活动,但是我有 System.NullReferenceException,我不知道它在哪里可以为空。
    • 更新:好的,问题出在 AlertBuilder 对话框上。我在 ReportDisplay 类中通过 Service 创建它们,以便从我想要的代码中的每个位置运行它,并构建它们我需要活动,我从中获取: var activity = this.GetService().Activity;这给了我空值......有什么想法吗?
    • 第二次更新:问题不是 AlertBuilder 对话框,而是警告迫使我在创建对象后处理它。现在它工作正常。非常感谢你!
    • 现在我在设备上安装后出现带有警告符号的“未安装应用程序”。链接错误还是什么?
    • 单独的问题 - 听起来像是一般的 android 或 mono droid 问题,而不是 mvvmcross 问题?
    猜你喜欢
    • 2015-12-25
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-28
    • 1970-01-01
    • 2021-05-26
    相关资源
    最近更新 更多