“本地类尚未加载"我的绑定错误 [英] "The native class hasn't been loading" error with my bindings
问题描述
我正在尝试为 GPUImage 项目创建绑定,但没有一个绑定类是在职的.例如,GPUImageView:
I'm trying to create bindings for GPUImage project, but none of binded classes is working. For example, GPUImageView:
在 ObjC 中,它是这样声明的(git 中的标头):
In ObjC it's declared like this (header in git):
@interface GPUImageView : UIView <GPUImageInput>
//then some fields, properties and methods I'm not interested in
所以,我的 ApiDefinition.cs 看起来像这样:
So, my ApiDefinition.cs looks like this:
namespace GPUImage
{
[BaseType (typeof(NSObject))]
[Model]
interface GPUImageInput {
}
[BaseType (typeof(UIView))]
interface GPUImageView : GPUImageInput {
[Export ("initWithFrame:")]
IntPtr Constructor(RectangleF frame);
}
}
LinkWithAttributes:
LinkWithAttributes:
[assembly: LinkWith ("libGPUImage.a", LinkTarget.Simulator | LinkTarget.ArmV7 | LinkTarget.ArmV7s, ForceLoad = true, Frameworks = "CoreMedia CoreVideo OpenGLES QuartzCore AVFoundation UIKit Foundation")]
它可以正常构建并创建 dll.但是当我尝试在我的项目中像这样使用它时:
It builds ok and creates dll. But when I try to use it in my project like this:
var iv = new GPUImageView (new RectangleF (0, 0, 100, 100));
抛出异常:
无法创建类型为GPUImage.GPUImageView"的本机实例:本机类尚未加载.可以通过将 Class.ThrowOnInitFailure 设置为 false 来忽略此条件.
Could not create an native instance of the type 'GPUImage.GPUImageView': the native class hasn't been loaded. It is possible to ignore this condition by setting Class.ThrowOnInitFailure to false.
在 MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure == false
iv
之后被创建,但无法使用(例如 AddSubview(iv)
不显示).
After MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure == false
iv
was created, but unusable (e.g. AddSubview(iv)
show nothing).
我认为 GPUImage.a 文件有问题,但我不知道如何以任何方式对其进行测试.
I suppose there is something wrong with GPUImage.a file, but I don't know how to test it in any way.
这是 7z,其中包含 2 个项目: TryingBindings -- 绑定本身;TryingGPUImage -- 正在使用的绑定;
Here is 7z with 2 projects in it: TryingBindings -- bindings themselves; TryingGPUImage -- bindings in use;
提前致谢.
推荐答案
感谢 Rolf Bjarne Kvinge
Thanks to Rolf Bjarne Kvinge
有两个问题:
1) 带有 LinkWith 属性的文件 (libGPUImage.linkwith.cs) 是没有编译.只需右键单击 TryingBindings 项目,添加,添加文件并选择它.
1) The file with the LinkWith attribute (libGPUImage.linkwith.cs) is not compiled. Just right-click the TryingBindings project, Add, Add files and select it.
2) 本机库不包含 i386(模拟器)的代码,仅包含手臂(设备).如果您自己构建本地库,则可以要么创建一个包含所有代码的通用库架构,或者您可以使用多个本机库,每个库支持一组不同的架构,并且每个原生库只有一个 LinkWith 属性.
2) The native library does not contain code for i386 (simulator), only arm (device). If you're building the native library yourself you can either create a universal library that contain code for all the architectures, or you can use several native libraries, each supporting a different set of architectures, and just have a LinkWith attribute for each native library.
这篇关于“本地类尚未加载"我的绑定错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!