I've recently started using Objective Sharpie to bind iOS libraries and I'm following the walkthrough on the developer site. I am able to bind the files successfully but the output ApiDefinition.cs file and Structs.cs file is huge, about 60 000 lines long. This is not meant to be the case. Can anyone tell me how to fix this issue please?
I have found that you need to limit the scope of the binding. Use the -scope pathTo/Headers parameter, assuming you have not done so already. If this does not help, share your simple lib and I'll have a look.
I am also assuming Sharpie used a [Verify] attribute on the generated property? I am also assuming that your method had no parameters? In this case the convention is to convert the method into a property. If you do not want this syntax, you are welcome to modify the definition. This is why the [Verify] attribute is there.
Best
Answers
I've had exactly the same issue... The ApiDefinition.cs and Structs.cs files are so huge that Visual Studio for Mac becomes unusably slow when trying to so much as look at these files.
I first tried the "Walkthrough" provided by Xamarin, and thought perhaps the issue was that they were exposing APIs from all header files (*.h). So as a test, I built an extremely simple static library in Objective-C with just a single method in a single class with a single header file. Even this resulted in tens of thousands of lines of code in both ApiDefinitions.cs and Structs.cs.
Even worse, when I finally located the code that was supposed to expose my one method, it had exposed it as a read-only property rather than a method. I wound up writing my ApiDefinitions.cs file manually, exposing my one method, and that worked fine... But I would like to understand how to use Objective Sharpie so that these things can be automated to some extent.
Is this a bug in Objective Sharpie, or are we just using it wrong? Any information would be greatly appreciated.
@JasperJian - If the library you're converting is Objective-C, I've seen other members in this forum suggesting a project called "objc-automatic" as a more successful route. Perhaps that will help.
Hi @JonathanBachelor
I have found that you need to limit the scope of the binding. Use the -scope pathTo/Headers parameter, assuming you have not done so already. If this does not help, share your simple lib and I'll have a look.
I am also assuming Sharpie used a [Verify] attribute on the generated property? I am also assuming that your method had no parameters? In this case the convention is to convert the method into a property. If you do not want this syntax, you are welcome to modify the definition. This is why the [Verify] attribute is there.
Best
Thanks Chris, I'll try to limit the scope of the binding and see if that makes a difference.
Thanks very much, @Chrisvanwyk!
I finally found a reference to the scope variable when in an "advanced" document. I have left feedback on the Walkthrough page, asking that the Objective Sharpie command be updated to talk about the Scope argument. As a beginner, the humongous files generated are not only intimidating and incomprehensible, they make Visual Studio so insanely slow that you can't even easily look through the files to try to understand what the heck all those lines are for. Hopefully the walkthrough will get an update... By hiding the scope argument in an article marked "Advanced", it leaves beginners like myself clueless.
Hello @Chrisvanwyk
I also have a similar issue. I have a static library with two header files.
It generates a massive size api definition and struct.cs file. I don't think limiting the scope will matter in this case.
On the side note, what does limiting the scope really means? Is it asking the sharpie tool to no look in to framework definitions as well?
Curious.
Just to get the background of the issue, I have this ePOS library and header files from EPSON POS SDK and I want to use it in my Xamarin Native (iOS and Android) projects. I was able to generate the bindings, but to be honest it is so daunting, I don't know where to begin.
Any pointer in right direction is appreciated.
Anurag
I cannot add link to the file.
@JasperJian @JonathanBachelor @Chrisvanwyk Is there any documentation on how to solve this problem? I'm having some trouble too and it never occurred in version 3.3 (I updated to 3.4 today)
I created a really simple header file
Objective Sharpie should only have to generate this in ApiDefinitions
but now it binds everything needed for UIKit
If I remove
#include <UIKit/UIKit.h>
as well as the UIView inheritance I get what I expect however I won't get the[BaseType (typeof(UIView))]
If I remove
#include <UIKit/UIKit.h>
while keeping the UIView inheritance I getcannot find interface declaration for 'UIView'
from Objective Sharpie.Is there a reason why every file in #include and #import are now part of ApiDefinitions and StructsAndEnums? This wasn't a problem for 3.3
@NashZhou from our documentation site:
My suggestion is to include the -scope parameter now by default.
@Chrisvanwyk
I might need more clarification on the proper command.
is the command I'm currently using and I still get bindings from UIKit. Objective Sharpie 3.4 is able to find the
MyView
header file located in TempHeaderFolder but I still get everything from UIKit. The only solution I have right now is downgrading to version 3.3 or weed out all of UIKit's bindings. Could you clarify what command should be used if scope isn't working?@NashZhou
I created the header file as you specified above and tested with Sharpie 3.4.0-c0f0e73
My header file is located in this folder /Users/xxx/Projects/BindingTest/Headers running the following command from the /Users/xxx/Projects/BindingTest folder:
sharpie bind -output TempBinding -namespace TempBinding -sdk iphoneos11.2 -scope Headers Headers/*.h -c -IHeaders -arch arm64
This created an ApiDefinitions.cs in /Users/xxx/Projects/BindingTest/TempBinding.
The contents from the ApiDefinitions.cs file is as follows:
I believe you need to change your command line so that the -scope as well as the -l folder path passed to clang match the ~/Desktop/TempHeaderFolder your header file is located in .
Hi, I'm going crazy in binding a framework. First I get a huge file so I set the scope and the files seem better, but I always get an error on a file and no way to get the binding to work.. My command is: sharpie bind -sdk iphoneos11.3 -output Bindings -namespace TestBindingNamirial -scope NamirialFEA.framework/Headers NamirialFEA.framework/Headers/*.h -c -INamirialFEA.framework/Headers -arch arm64 -v
Can you https://forums.xamarin.com/profile/Chrisvanwyk the framework give some hints?
Here is the framework @Chrisvanwyk
Hi @MatteoMonizza
Leave your sharpie command line statement as is.
Edit
NamirialFEA.framework/Headers/NamirialFEA.h
and change all imports from#import <NamirialFEA/*.h>
to#import <*.h>
This worked for me.
Done, now I can run it but when I try to call the first method TestBindingNamirial.FCManager.GetManager().Init(); it does nothing and if I set a breakpoint it never stop..
I am new in Xamarin development. Can you please give me command how I can limit to scope in our project. We are getting 25000 lines in .cs file
Hi !
There is my terminal output/input:
It doesn't work and I am not sure to understand why.. I have XCode 9.2 because otherwise it crash directly with an unhandled exception...
I tried with others parameters but it generates 18k lines of code for APIDefinitions and 25k for StructsAndEnums
I only have that code:
Test2.h
Test2.m
I am just learning so I might have missed something but I am stuck atm
I am trying to bind my swift framework with Xamarin. I am using objective Sharpie for this.
I have set 'Enable Bitcode' to 'No' in the framework.
Built the framework for running.
Use the following command for binding the header file.
https://test-dpc.com/ file.
SnapTube TubeMate Test Dpc
I think you want
-scope Test2/Test2 Test2/Test2/*.h
rather than-scope Test2/build Test2/Test2/*.h
Now that Sharpie has had a chance to mature, is there a definitive guide / doc on its use? I have tried various combinations of sharpie command lines with -F, -I, -scope, -c args because different docs and forum discussions offer different suggestions. I'm trying to create a binding library for use with Xamarin.Forms from either a 3rd-party framework or a 3rd-party static library (the 3rd party offers both framework and static library). Thank you.
I am using this command, but it is generating huge, big ApiDefinations.cs file , anyone have solution for this ?
sharpie bind --output Binding -scope build/Headers --namespace=samefacelibrary --sdk=iphoneos13.2 /Users/osx/Desktop/samefacelibrary/samefacelibrary/SameFace.h