0

I needed a sketch/painting control for my Xamarin.iOS project, and while I couldn't seem to find one compatible with C# I did find a good component available written in Objective C. https://github.com/acerbetti/ACEDrawingView

I've done Xamarin bindings before, so I had hoped that the process would be fairly simple, but unfortunately I've hit a few roadblocks along the way.

I started off creating my static library and used an ant build script to make a FAT binary to cover devices and the simulator:

snippet of my ant script

AceDrawingViewSDK.a: libAceDrawingView-i386.a libAceDrawingView-armv7.a   libAceDrawingView-armv7s.a libAceDrawingView-arm64.a xcrun -sdk iphoneos lipo -create -output $@ $^

Next, I ran

sharpie bind --sdk=iphoneos10.1 *.h

on the header files to get my ApiDefinitions and Structs and Enum files.

I checked and removed a the Verify attributes. (They all looked fine.) But this is where some of my other issues started.

The type ACEDrawingLabelViewTransform' already contains a definition forTransform' (CS0102) (AceDrawingViewBinding). 

For the sake of just trying to move on and get something working, I just commented out this reference.

I then got multiple problems similar to this:

The type or namespace name `IACEDrawingTool' could not be found. Are you missing an assembly reference? (CS0246) (AceDrawingViewBinding)

I figured it related to this:

// @interface ACEDrawingPenTool : UIBezierPath 
[BaseType(typeof(UIBezierPath))]
interface ACEDrawingPenTool : IACEDrawingTool

and this:

// @protocol ACEDrawingTool 
[Protocol, Model]
[BaseType(typeof(NSObject))]
interface ACEDrawingTool

I tried to fix this my making the interface name consistent (I tried both IACEDrawingTool and ACEDrawingTool.) Doing this got past this error and allowed me to compile

One of my enums came out as

[Native]
 public enum ACEDrawingMode : nuint
{
Scale,
OriginalSize
}

I couldn't find how to handle [Native] in this case (so once again, for testing sake I removed it.) I tried using removing the nuint from the enum and using uint. Either approach seemed to fix the error.

So with those errors fixed I was able to generate the .dll from my binding project and add it to my main project.

Now, I am getting 2 more issues.

If I build and deploy to the simulator I am able to run my app up until the point that I try to create a new instance of the ACEDrawingView from the binding. I get:

Could not create an native instance of the type 'ACEDrawingView': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.

If I try to build and deploy to my phone I get different errors in the build phase which prevents it from launching on the device at all:

MTOUCH: error MT5211: Native linking failed, undefined Objective-C class: ACEDrawingArrowTool. The symbol 'OBJC_CLASS$ACEDrawingArrowTool' could not be found in any of the libraries or frameworks linked with your application.
MTOUCH: error MT5211: Native linking failed, undefined Objective-C class: ACEDrawingDraggableTextTool. The symbol '_OBJC_CLASS$ACEDrawingDraggableTextTool' could not be found in any of the libraries or frameworks linked with your application.
MTOUCH: error MT5211: Native linking failed, undefined Objective-C class: ACEDrawingEllipseTool. The symbol '_OBJC_CLASS$_ACEDrawingEllipseTool' could not be found in any of the libraries or frameworks linked with your application.

...and so on.

I've tried going back, rereading and redoing steps and have tried to reuse some of the scripts and settings from my previous successful bindings with no luck.

Does anyone have suggestions for what might fix these issues?

cain
  • 1,028
  • 1
  • 12
  • 26

1 Answers1

0

The type or namespace name `IACEDrawingTool' could not be found.

Add a new interface, like this interface IACEDrawingTool{ }

public enum ACEDrawingMode : nuint

Change the nuint to ulong

Lei Kan
  • 487
  • 7
  • 20