Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The native class hasn't been loading" error with my bindings

I'm trying to create bindings for GPUImage project, but none of binded classes is working. For example, GPUImageView:

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

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:

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

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));

Exception throwed:

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.

Stacktrace

After MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure == false iv was created, but unusable (e.g. AddSubview(iv) show nothing).

I suppose there is something wrong with GPUImage.a file, but I don't know how to test it in any way.

Here is 7z with 2 projects in it: TryingBindings -- bindings themselves; TryingGPUImage -- bindings in use;

Thanks in advance.

P.S. Here is the link to this post on xamarin forums.

like image 649
folex Avatar asked Mar 29 '13 11:03

folex


Video Answer


1 Answers

Thanks to Rolf Bjarne Kvinge

There are two problems:

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) 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.

Bug 11497

like image 52
folex Avatar answered Oct 14 '22 07:10

folex