Forum Xamarin.iOS

Problems Binding an Open Source Library.

candersoncanderson USMember ✭✭

I'm been working on this for a couple of days now with no success. I've previously done other bindings, but this one is giving me problems and I can't seem to figure out what is going wrong.

I'm trying to create a binding for

I initially started by running objective sharpie on the pod (which worked for the most part) but when I was doing some further work on it I read that it didn't create a library that was useable on the simulator. So I used the source code to create a static library project and built my own FAT binary file from my make file.

I did my usual procedure to build for individual platoforms and then I combined the multiple binaries like this:
AceDrawingViewSDK.a: libAceDrawingView-i386.a libAceDrawingView-armv7.a libAceDrawingView-armv7s.a libAceDrawingView-arm64.a
xcrun -sdk iphoneos lipo -create -output [email protected] $^

Next, I ran [sharpie bind --sdk=iphoneos10.1 *.h] on the code to get my ApiDefinitions and Structs and Enum files. (These turned out basically the same as when I had run them on the pod initially.)

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 got multiple problems similar to this:
The type or namespace name `IACEDrawingTool' could not be found. Are you missing an assembly reference? (CS0246) (AceDrawingViewBinding)

related to this:
// @interface ACEDrawingPenTool : UIBezierPath
interface ACEDrawingPenTool : IACEDrawingTool

and this
// @protocol ACEDrawingTool
[Protocol, Model]
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

public enum ACEDrawingMode : nuint

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:
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?

Here are the sharpie generated files before I have made my corrections if they may help:

using System;
using ObjCRuntime;

public enum ACEDrawingToolType : uint

public enum ACEDrawingMode : nuint

using System;
using CoreGraphics;
using Foundation;
using ObjCRuntime;
using UIKit;

// @interface ACEDrawingLabelView : UIView
[BaseType (typeof(UIView))]
interface ACEDrawingLabelView
// @property (readonly, nonatomic) NSString * textValue;
[Export ("textValue")]
string TextValue { get; }

// @property (nonatomic, strong) UIColor * textColor;
[Export ("textColor", ArgumentSemantic.Strong)]
UIColor TextColor { get; set; }

// @property (nonatomic, strong) UIColor * borderColor;
[Export ("borderColor", ArgumentSemantic.Strong)]
UIColor BorderColor { get; set; }

// @property (copy, nonatomic) NSString * fontName;
[Export ("fontName")]
string FontName { get; set; }

// @property (assign, nonatomic) CGFloat fontSize;
[Export ("fontSize")]
nfloat FontSize { get; set; }

// @property (nonatomic, strong) UIImage * closeImage;
[Export ("closeImage", ArgumentSemantic.Strong)]
UIImage CloseImage { get; set; }

// @property (nonatomic, strong) UIImage * rotateImage;
[Export ("rotateImage", ArgumentSemantic.Strong)]
UIImage RotateImage { get; set; }

// @property (copy, nonatomic) NSAttributedString * attributedPlaceholder;
[Export ("attributedPlaceholder", ArgumentSemantic.Copy)]
NSAttributedString AttributedPlaceholder { get; set; }

[Wrap ("WeakDelegate")]
ACEDrawingLabelViewDelegate Delegate { get; set; }

// @property (nonatomic, weak) id<ACEDrawingLabelViewDelegate> delegate;
[NullAllowed, Export ("delegate", ArgumentSemantic.Weak)]
NSObject WeakDelegate { get; set; }

// @property (nonatomic) BOOL showsContentShadow;
[Export ("showsContentShadow")]
bool ShowsContentShadow { get; set; }

// @property (getter = isEnableClose, nonatomic) BOOL enableClose;
[Export ("enableClose")]
bool EnableClose { [Bind ("isEnableClose")] get; set; }

// @property (getter = isEnableRotate, nonatomic) BOOL enableRotate;
[Export ("enableRotate")]
bool EnableRotate { [Bind ("isEnableRotate")] get; set; }

// @property (getter = isEnableMoveRestriction, nonatomic) BOOL enableMoveRestriction;
[Export ("enableMoveRestriction")]
bool EnableMoveRestriction { [Bind ("isEnableMoveRestriction")] get; set; }

// @property (readonly, nonatomic) BOOL isEditing;
[Export ("isEditing")]
bool IsEditing { get; }

// -(void)hideEditingHandles;
[Export ("hideEditingHandles")]
void HideEditingHandles ();

// -(void)showEditingHandles;
[Export ("showEditingHandles")]
void ShowEditingHandles ();

// -(CGFloat)textAlpha;
// -(void)setTextAlpha:(CGFloat)alpha;
[Export ("textAlpha")]
[Verify (MethodToProperty)]
nfloat TextAlpha { get; set; }

// -(void)resizeInRect:(CGRect)rect;
[Export ("resizeInRect:")]
void ResizeInRect (CGRect rect);


// @protocol ACEDrawingLabelViewDelegate
[Protocol, Model]
[BaseType (typeof(NSObject))]
interface ACEDrawingLabelViewDelegate
// @optional -(void)labelViewDidClose:(ACEDrawingLabelView *)label;
[Export ("labelViewDidClose:")]
void LabelViewDidClose (ACEDrawingLabelView label);

// @optional -(void)labelViewWillShowEditingHandles:(ACEDrawingLabelView *)label;
[Export ("labelViewWillShowEditingHandles:")]
void LabelViewWillShowEditingHandles (ACEDrawingLabelView label);

// @optional -(void)labelViewDidShowEditingHandles:(ACEDrawingLabelView *)label;
[Export ("labelViewDidShowEditingHandles:")]
void LabelViewDidShowEditingHandles (ACEDrawingLabelView label);

// @optional -(void)labelViewDidHideEditingHandles:(ACEDrawingLabelView *)label;
[Export ("labelViewDidHideEditingHandles:")]
void LabelViewDidHideEditingHandles (ACEDrawingLabelView label);

// @optional -(void)labelViewDidStartEditing:(ACEDrawingLabelView *)label;
[Export ("labelViewDidStartEditing:")]
void LabelViewDidStartEditing (ACEDrawingLabelView label);

// @optional -(void)labelViewDidBeginEditing:(ACEDrawingLabelView *)label;
[Export ("labelViewDidBeginEditing:")]
void LabelViewDidBeginEditing (ACEDrawingLabelView label);

// @optional -(void)labelViewDidChangeEditing:(ACEDrawingLabelView *)label;
[Export ("labelViewDidChangeEditing:")]
void LabelViewDidChangeEditing (ACEDrawingLabelView label);

// @optional -(void)labelViewDidEndEditing:(ACEDrawingLabelView *)label;
[Export ("labelViewDidEndEditing:")]
void LabelViewDidEndEditing (ACEDrawingLabelView label);


// @interface DynamicFontSize (UITextField)
[BaseType (typeof(UITextField))]
interface UITextField_DynamicFontSize
// -(void)adjustsFontSizeToFillRect:(CGRect)newBounds;
[Export ("adjustsFontSizeToFillRect:")]
void AdjustsFontSizeToFillRect (CGRect newBounds);

// -(void)adjustsWidthToFillItsContents;
[Export ("adjustsWidthToFillItsContents")]
void AdjustsWidthToFillItsContents ();


// @interface ACEDrawingLabelViewTransform : NSObject
[BaseType (typeof(NSObject))]
interface ACEDrawingLabelViewTransform
// +(instancetype)transform:(CGAffineTransform)transform atCenter:(CGPoint)center withBounds:(CGRect)bounds;
[Export ("transform:atCenter:withBounds:")]
ACEDrawingLabelViewTransform Transform (CGAffineTransform transform, CGPoint center, CGRect bounds);

// @property (readonly, nonatomic) CGAffineTransform transform;
[Export ("transform")]
CGAffineTransform Transform { get; }

// @property (readonly, nonatomic) CGPoint center;
[Export ("center")]
CGPoint Center { get; }

// @property (readonly, nonatomic) CGRect bounds;
[Export ("bounds")]
CGRect Bounds { get; }


// @protocol ACEDrawingTool
[Protocol, Model]
[BaseType (typeof(NSObject))]
interface ACEDrawingTool
// @required @property (nonatomic, strong) UIColor * lineColor;
[Export ("lineColor", ArgumentSemantic.Strong)]
UIColor LineColor { get; set; }

// @required @property (assign, nonatomic) CGFloat lineAlpha;
[Export ("lineAlpha")]
nfloat LineAlpha { get; set; }

// @required @property (assign, nonatomic) CGFloat lineWidth;
[Export ("lineWidth")]
nfloat LineWidth { get; set; }

// @required -(void)setInitialPoint:(CGPoint)firstPoint;
[Export ("setInitialPoint:")]
void SetInitialPoint (CGPoint firstPoint);

// @required -(void)moveFromPoint:(CGPoint)startPoint toPoint:(CGPoint)endPoint;
[Export ("moveFromPoint:toPoint:")]
void MoveFromPoint (CGPoint startPoint, CGPoint endPoint);

// @required -(void)draw;
[Export ("draw")]
void Draw ();

// @required -(ACEDrawingToolState *)captureToolState;
[Export ("captureToolState")]
[Verify (MethodToProperty)]
ACEDrawingToolState CaptureToolState { get; }

// @optional -(void)applyToolState:(ACEDrawingToolState *)state;
[Export ("applyToolState:")]
void ApplyToolState (ACEDrawingToolState state);

// @optional -(id)capturePositionObject;
[Export ("capturePositionObject")]
[Verify (MethodToProperty)]
NSObject CapturePositionObject { get; }


// @interface ACEDrawingPenTool : UIBezierPath
[BaseType (typeof(UIBezierPath))]
interface ACEDrawingPenTool : IACEDrawingTool
// -(CGRect)addPathPreviousPreviousPoint:(CGPoint)p2Point withPreviousPoint:(CGPoint)p1Point withCurrentPoint:(CGPoint)cpoint;
[Export ("addPathPreviousPreviousPoint:withPreviousPoint:withCurrentPoint:")]
CGRect AddPathPreviousPreviousPoint (CGPoint p2Point, CGPoint p1Point, CGPoint cpoint);

// @interface ACEDrawingEraserTool : ACEDrawingPenTool
[BaseType (typeof(ACEDrawingPenTool))]
interface ACEDrawingEraserTool

// @interface ACEDrawingLineTool : NSObject
[BaseType (typeof(NSObject))]
interface ACEDrawingLineTool : IACEDrawingTool

// @interface ACEDrawingDraggableTextTool : NSObject
[BaseType (typeof(NSObject))]
interface ACEDrawingDraggableTextTool : IACEDrawingTool
// @property (nonatomic, weak) ACEDrawingView * drawingView;
[Export ("drawingView", ArgumentSemantic.Weak)]
ACEDrawingView DrawingView { get; set; }

// @property (readonly, nonatomic) ACEDrawingLabelView * labelView;
[Export ("labelView")]
ACEDrawingLabelView LabelView { get; }

// -(void)capturePosition;
[Export ("capturePosition")]
void CapturePosition ();

// -(void)hideHandle;
[Export ("hideHandle")]
void HideHandle ();

// -(void)undraw;
[Export ("undraw")]
void Undraw ();

// -(BOOL)canRedo;
[Export ("canRedo")]
[Verify (MethodToProperty)]
bool CanRedo { get; }

// -(BOOL)redo;
[Export ("redo")]
[Verify (MethodToProperty)]
bool Redo { get; }

// -(BOOL)canUndo;
[Export ("canUndo")]
[Verify (MethodToProperty)]
bool CanUndo { get; }

// -(void)undo;
[Export ("undo")]
void Undo ();


// @interface ACEDrawingRectangleTool : NSObject
[BaseType (typeof(NSObject))]
interface ACEDrawingRectangleTool : IACEDrawingTool
// @property (assign, nonatomic) BOOL fill;
[Export ("fill")]
bool Fill { get; set; }

// @interface ACEDrawingEllipseTool : NSObject
[BaseType (typeof(NSObject))]
interface ACEDrawingEllipseTool : IACEDrawingTool
// @property (assign, nonatomic) BOOL fill;
[Export ("fill")]
bool Fill { get; set; }

// @interface ACEDrawingArrowTool : NSObject
[BaseType (typeof(NSObject))]
interface ACEDrawingArrowTool : IACEDrawingTool

// @interface ACEDrawingToolState : NSObject
[BaseType (typeof(NSObject))]
interface ACEDrawingToolState
// +(instancetype)stateForTool:(id)tool;
[Export ("stateForTool:")]
ACEDrawingToolState StateForTool (ACEDrawingTool tool);

// +(instancetype)stateForTool:(id<ACEDrawingTool>)tool capturePosition:(BOOL)capture;
[Export ("stateForTool:capturePosition:")]
ACEDrawingToolState StateForTool (ACEDrawingTool tool, bool capture);

// @property (readonly, nonatomic) id<ACEDrawingTool> tool;
[Export ("tool")]
ACEDrawingTool Tool { get; }

// @property (readonly, nonatomic) BOOL hasPositionObject;
[Export ("hasPositionObject")]
bool HasPositionObject { get; }

// @property (readonly, nonatomic) id positionObject;
[Export ("positionObject")]
NSObject PositionObject { get; }


// @interface ACEDrawingView : UIView
[BaseType (typeof(UIView))]
interface ACEDrawingView : IACEDrawingLabelViewDelegate
// @property (assign, nonatomic) ACEDrawingToolType drawTool;
[Export ("drawTool", ArgumentSemantic.Assign)]
ACEDrawingToolType DrawTool { get; set; }

// @property (nonatomic, strong) id<ACEDrawingTool> customDrawTool;
[Export ("customDrawTool", ArgumentSemantic.Strong)]
ACEDrawingTool CustomDrawTool { get; set; }

[Wrap ("WeakDelegate")]
ACEDrawingViewDelegate Delegate { get; set; }

// @property (assign, nonatomic) id<ACEDrawingViewDelegate> delegate;
[NullAllowed, Export ("delegate", ArgumentSemantic.Assign)]
NSObject WeakDelegate { get; set; }

// @property (nonatomic, strong) UIColor * lineColor;
[Export ("lineColor", ArgumentSemantic.Strong)]
UIColor LineColor { get; set; }

// @property (assign, nonatomic) CGFloat lineWidth;
[Export ("lineWidth")]
nfloat LineWidth { get; set; }

// @property (assign, nonatomic) CGFloat lineAlpha;
[Export ("lineAlpha")]
nfloat LineAlpha { get; set; }

// @property (assign, nonatomic) CGFloat edgeSnapThreshold;
[Export ("edgeSnapThreshold")]
nfloat EdgeSnapThreshold { get; set; }

// @property (assign, nonatomic) ACEDrawingMode drawMode;
[Export ("drawMode", ArgumentSemantic.Assign)]
ACEDrawingMode DrawMode { get; set; }

// @property (nonatomic, strong) NSString * draggableTextFontName;
[Export ("draggableTextFontName", ArgumentSemantic.Strong)]
string DraggableTextFontName { get; set; }

// @property (nonatomic, strong) UIImage * draggableTextCloseImage;
[Export ("draggableTextCloseImage", ArgumentSemantic.Strong)]
UIImage DraggableTextCloseImage { get; set; }

// @property (nonatomic, strong) UIImage * draggableTextRotateImage;
[Export ("draggableTextRotateImage", ArgumentSemantic.Strong)]
UIImage DraggableTextRotateImage { get; set; }

// @property (readonly, nonatomic, strong) UIImage * image;
[Export ("image", ArgumentSemantic.Strong)]
UIImage Image { get; }

// @property (nonatomic, strong) UIImage * backgroundImage;
[Export ("backgroundImage", ArgumentSemantic.Strong)]
UIImage BackgroundImage { get; set; }

// @property (readonly, nonatomic) NSUInteger undoSteps;
[Export ("undoSteps")]
nuint UndoSteps { get; }

// -(void)loadImage:(UIImage *)image;
[Export ("loadImage:")]
void LoadImage (UIImage image);

// -(void)loadImageData:(NSData *)imageData;
[Export ("loadImageData:")]
void LoadImageData (NSData imageData);

// -(void)clear;
[Export ("clear")]
void Clear ();

// -(void)prepareForSnapshot;
[Export ("prepareForSnapshot")]
void PrepareForSnapshot ();

// -(BOOL)canUndo;
[Export ("canUndo")]
[Verify (MethodToProperty)]
bool CanUndo { get; }

// -(void)undoLatestStep;
[Export ("undoLatestStep")]
void UndoLatestStep ();

// -(BOOL)canRedo;
[Export ("canRedo")]
[Verify (MethodToProperty)]
bool CanRedo { get; }

// -(void)redoLatestStep;
[Export ("redoLatestStep")]
void RedoLatestStep ();

// -(UIImage *)applyDrawToImage:(UIImage *)baseImage;
[Export ("applyDrawToImage:")]
UIImage ApplyDrawToImage (UIImage baseImage);

// -(void)commitAndDiscardToolStack;
[Export ("commitAndDiscardToolStack")]
void CommitAndDiscardToolStack ();


// @protocol ACEDrawingViewDelegate
[Protocol, Model]
[BaseType (typeof(NSObject))]
interface ACEDrawingViewDelegate
// @optional -(void)drawingView:(ACEDrawingView *)view willBeginDrawUsingTool:(id)tool;
[Export ("drawingView:willBeginDrawUsingTool:")]
void WillBeginDrawUsingTool (ACEDrawingView view, ACEDrawingTool tool);

// @optional -(void)drawingView:(ACEDrawingView *)view didEndDrawUsingTool:(id<ACEDrawingTool>)tool;
[Export ("drawingView:didEndDrawUsingTool:")]
void DidEndDrawUsingTool (ACEDrawingView view, ACEDrawingTool tool);

// @optional -(void)drawingView:(ACEDrawingView *)view didRedoDrawUsingTool:(id<ACEDrawingTool>)tool;
[Export ("drawingView:didRedoDrawUsingTool:")]
void DidRedoDrawUsingTool (ACEDrawingView view, ACEDrawingTool tool);

// @optional -(void)drawingView:(ACEDrawingView *)view didUndoDrawUsingTool:(id<ACEDrawingTool>)tool;
[Export ("drawingView:didUndoDrawUsingTool:")]
void DidUndoDrawUsingTool (ACEDrawingView view, ACEDrawingTool tool);


Sign In or Register to comment.