【问题标题】:"The native class hasn't been loading" error with my bindings我的绑定出现“本机类尚未加载”错误
【发布时间】:2013-03-29 11:11:04
【问题描述】:

我正在尝试为GPUImage 项目创建绑定,但绑定的类都不起作用。 比如GPUImageView:

在 ObjC 中它是这样声明的 (header in git):

@interface GPUImageView : UIView <GPUImageInput>
//then some fields, properties and methods I'm not interested in

所以,我的 ApiDefinition.cs 看起来像这样:

namespace GPUImage
{
    [BaseType (typeof(NSObject))]
    [Model]
    interface GPUImageInput {
    }

    [BaseType (typeof(UIView))]
    interface GPUImageView : GPUImageInput {
        [Export ("initWithFrame:")]
        IntPtr Constructor(RectangleF frame);
    }
}

LinkWithAttributes:

[assembly: LinkWith ("libGPUImage.a", LinkTarget.Simulator | LinkTarget.ArmV7 | LinkTarget.ArmV7s, ForceLoad = true, Frameworks = "CoreMedia CoreVideo OpenGLES QuartzCore AVFoundation UIKit Foundation")]

它可以构建并创建 dll。但是当我尝试在我的项目中这样使用它时:

var iv = new GPUImageView (new RectangleF (0, 0, 100, 100));

抛出异常:

无法创建“GPUImage.GPUImageView”类型的本机实例:本机类尚未加载。 可以通过将 Class.ThrowOnInitFailure 设置为 false 来忽略此条件。

Stacktrace

MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure == false iv 创建后,但无法使用(例如AddSubview(iv) 不显示任何内容)。

我认为 GPUImage.a 文件有问题,但我不知道如何以任何方式对其进行测试。

Here is 7z 包含 2 个项目: TryingBindings -- 绑定本身; TryingGPUImage -- 正在使用的绑定;

提前致谢。

附: Here is the link to this post on xamarin forums.

【问题讨论】:

  • 能把头文件分享到objective-c库吗?我在你的 7z 文件中没有看到它们。
  • 空构造函数对你有用吗?我在这里没有看到任何 init 方法。
  • 不,同样的例外。同样的异常也发生在我尝试绑定的 5 个其他构造函数中的 5 个上。顺便说一句,你能看到任何方法来检查 GPUImage.a 在某种意义上是否有效吗?
  • 不要编辑问题说已解决。自己回答并接受答案。

标签: ios binding xamarin.ios gpuimage


【解决方案1】:

感谢 Rolf Bjarne Kvinge

有两个问题:

1) 具有 LinkWith 属性的文件 (libGPUImage.linkwith.cs) 是 未编译。只需右键单击 TryingBindings 项目,添加,添加 文件并选择它。

2) 本机库不包含 i386(模拟器)的代码,只有 手臂(设备)。如果您自己构建本机库,则可以 要么创建一个包含所有代码的通用库 架构,或者您可以使用多个本机库,每个 支持一组不同的架构,并且每个原生库只有一个 LinkWith 属性。

Bug 11497

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多