我在大多数 View 中成功使用了 Mvx.MvxFrameControl。其中一个 View 使用从头开始构建的自定义控件。仅在 Release模式下,在膨胀此 View 时,应用会崩溃。
日志显示一个方法已经被优化掉并且丢失了。
at <unknown> <0xffffffff>
at (wrapper managed-to-native) object.wrapper_native_...
at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue[])
at Android.Views.LayoutInflater.Inflate(int, Android.Views.ViewGroup)
at Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContext.CommonInflate(int,Android.View.ViewGroup, IMvxLayoutInfactorFactory)
....
所以我尝试将这些行添加到 MainApp 类的 MainApp 构造函数中。
public class MainApp : Application
{
public MainApp(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
//For linker only
Android.Views.LayoutInflater inflater = null;
if(inflater != null)
inflater.Inflate(0, null);
}
我希望链接器不会优化该方法。但没有运气。该方法仍然缺失。如何解决这个问题?
编辑:我在 Android 4.3 模拟器的 Release模式下尝试了 Cheesebaron.HorizontalListView.Demo 项目,但它也崩溃了。
编辑:似乎链接问题与所有派生自 AdatperView<T>
的类有关
编辑:更多堆栈跟踪
01-03 03:20:46.185 E/mono-rt ( 2106): Stacktrace:
01-03 03:20:46.185 E/mono-rt ( 2106):
01-03 03:20:46.195 E/mono-rt ( 2106): at <unknown> <0xffffffff>
01-03 03:20:46.195 E/mono-rt ( 2106): at (wrapper managed-to-native) object.wrapper_native_0xb6360af0 (intptr,intptr,intptr,Android.Runtime.JValue[]) <0xffffffff>
01-03 03:20:46.195 E/mono-rt ( 2106): at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue[]) <0x00068>
01-03 03:20:46.195 E/mono-rt ( 2106): at Android.Views.LayoutInflater.Inflate (int,Android.Views.ViewGroup) <0x00147>
最佳答案
这是 a bug .解决方法是提供 custom linker script通过使用 LinkDescription
的 Build 操作 和文件内容向您的项目添加一个新文件:
<linker>
<assembly fullname="Mono.Android">
<type fullname="Android.Widget.AdapterView">
<method name="GetGetAdapterHandler" />
<method name="GetSetAdapter_Landroid_widget_Adapter_Handler" />
</type>
</assembly>
</linker>
关于链接器和 LayoutInflater.Inflate(int, Android.Views.ViewGroup),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20873303/