Random things of a random world

Sami's Page

  • Join Us on Facebook!
  • Follow Us on Twitter!
  • LinkedIn
  • Subcribe to Our RSS Feed

Adding a Framework to Xamarin iOS Project

So, I needed to add a framework to a Xamarin iOS project. Should be easy, right? I mean, on Android it's quite easy to just generate the binding and use it. But with iOS not so much. I do understand that it's a bit different to get metadata from a Java bytecode library than a native iOS library, but looks like the problems are completely elsewhere.

First I installed Objective Sharpie since that was said to be the easiest way. The library is available as a CocoaPod (though just as a binary, but still). For some reason it created its own pod repo etc and didn't use the one I already have. It does have an option to set the directory but I don't dare do that since Xamarin. So a lot of waiting...

I noticed that it would send telemetry data to Xamarin so I added options to disable that. You know what? Surprisingly it didn't work. It still said it sent the data to Xamarin. Typical Xamarin.

sharpie -tlm-do-not-submit -tlm-do-not-identify pod bind

Submitting usage data to Xamarin...
  Submitted - thank you for helping to improve Objective Sharpie!

 

It created two files: XXX_ApiDefinition.cs and XXX_StructsAndEnums.cs. It said it created them without the XXX prefix, but oh well. Xamarin. Says one and does another.

Then I created a binding project. It also creates those files so I removed them and added the ones I had. Build. No apidefinition file specified. Oh, I have to set the ApiDefinitions.cs to be ObjcBindingApiDefinition and StructsAndEnums.cs to be ObjcBindingCoreSource in their properties. Ok.

Build again. Whines that it can't find the namespace XXX. Hmm, how do I add a framework into this? I've only seen libraries being added, so no idea. Native references? It accepted a framework. Ok.

Build again. No change. Still can't find it. Also whines about nint and other types which should be in System namespace, in Xamarin.iOS assembly. It's included. Still not found. Nice. I even tried to add the binary inside the framework and set it to ObjcBindingNativeLibrary, but no help. It just won't build.

Looks like the files also have no namespaces defined so I'll have to do that manually. Oh well, not a big thing, but still.

I'll change all the nints to ints and nuints to uints, maybe that'll help. Sure, it compiles. But now it cries about using bool* in a definition. Ugh. Remove method, I might not need it.

Then a huge list of errors from the Verify attribute, which can't be found. So they changed something? Let's remove all of those. All dozens and dozens of them...

The attribute 'StaticAttribute' cannot be applied multiple times. Nice. Let's remove those also...

Editor also whines it can't find attributes (Static, BaseType etc) so no idea if they're correct or not. Impossible to know.

"Do not know how to trampoline for Boolean * arg3" yeah, another bool* in the code. Commenting out.

Lots of errors about types not being able to be used as TKey in dictionaries since they don't inherit from INativesomething. Why don't they? It's not my fault you don't make them proper yourself. Commenting out those methods...

Then finally it kinda compiles but the next whine is using int/uint on enumerations. Must be long/ulong. Change it again...

Then running into "unknown kind byte*" in a method definition. So unsafe pointers can't be used? How to fix this then...

Commented out everything. Next errors: defining methods in static classes. Umm, why are they static? Oh, there's a CategoryAttribute on each and every one of them. For no reason. Remove that, they become non-static I guess. Next...

Now I have a building library. I have no idea what it does, does it work, can I use it. That remains to be seen. I think I'll still go the route of actually building a wrapper library that handles using this API and just export the methods I actually need to Xamarin. Since I can't at this point convert everything to native code. Would be such a bliss.

It's so nice that Xamarin has such good documentation which only tells how to create the cs files but fails to explain how to actually get it to compile after that. "Add to a binding project" is not very helpful when it just doesn't work. And documentation is most likely very old and maybe outdated even. At least dead links are there (reported, of course).

So, how to proceed? Will a simple addition of a native library take a day or more to complete when Xamarin should be enhancing my productivity? We shall see. At least it isn't easy by any means. So, as always, stay away.

Or if you really have to, make a separate ObjC project which has an interface you can control explicitly. That way you know how to write the bindings for Xamarin. That's what I have to do know. I'll miss on all the nice things Xamarin might have to offer, I can't debug the code easily and it'll take a lot of time to do since I have to first create a separate application and get everything working before linking that into my actual app.

This will take several days it seems...

Add comment

Loading