链接器和 LayoutInflater.Inflate(int, Android.Views.ViewGroup)

标签 linker xamarin.android

我在大多数 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.Horizo​​ntalListView.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通过使用 LinkDescriptionBuild 操作 和文件内容向您的项目添加一个新文件:

<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/

相关文章:

c - 从 Leptonica 图像处理库执行代码示例

c - (&) 的地址从符号表中获取值

c - 如何将 VSTS .lib 转换为 MinGW .a?

c++ - 链接后的大型 C++ 静态库文件

xamarin.android - Android Mono 上 TextView 中的 HTML 样式

c# - 如何在 xamarin.forms 中读取图像源或图像名称?

c++ - 使用 comsupp.lib 的内部链接器错误

android - 如何在 Xamarin.Android 中保持 Button.Pressed 状态?

android - 单色机器人 : Unsigned Binary upload to Amazon

android - 多种设备密度和 Xamarin Android