xamarin - 与目标 Sharpie 绑定(bind)会输出巨大的文件

标签 xamarin xamarin.ios objective-sharpie

我正在尝试将我的 swift 框架与 Xamarin 绑定(bind)。为此,我使用客观的记号笔。

  • 我已在框架中将“启用位码”设置为“否”。
  • 构建了运行框架。
  • 使用以下命令绑定(bind)头文件。

sharpie bind -sdk iphoneos11.1 MyFramework.framework/Headers/MyFramework-Swift.h -output=MyFrameworkCS -namespace=MyFramework

我得到了 APIDefinitions.cs 文件,但它有超过 79000 行,并且有很多错误。 StructsAndEnums.cs 文件也很大。

我的框架(和 .h 文件)仅具有 UIKit、AVFoundation 和 Foundation 的导入语句。但 APIDefinitions.cs 有这个。

using System;
using AVFoundation;
using AudioToolbox;
using AudioUnit;
using CloudKit;
using CoreAnimation;
using CoreAudio;
using CoreData;
using CoreFoundation;
using CoreGraphics;
using CoreImage;
using CoreLocation;
using CoreMIDI;
using CoreMedia;
using CoreMidi;
using CoreText;
using CoreVideo;
using Darwin;
using Dispatch;
using FileProvider;
using Foundation;
using HyperSecureSDK;
using IOSurface;
using ImageIO;
using Intents;
using MediaToolbox;
using Metal;
using ObjCRuntime;
using ObjectiveC;
using OpenGLES;
using Security;
using UIKit;
using simd;

我对 Xamarin 非常陌生,并且非常困在这里。任何帮助将不胜感激!

最佳答案

您需要定义一个范围,以便并非所有其他库都显示在您的 APIDefinition.cs 中,如 https://developer.xamarin.com/guides/cross-platform/macios/binding/objective-sharpie/examples/advanced/ 中所述。

You will notice that we passed a -scope build/Headers argument to Objective Sharpie. Because C and Objective-C libraries must #import or include other header files that are implementation details of the library and not API you wish to bind, the -scope argument tells Objective Sharpie to ignore any API that is not defined in a file somewhere within the -scope directory.

You will find the -scope argument is often optional for cleanly implemented libraries, however there is no harm in explicitly providing it.

这应该删除 APIDefinition.cs 中其他库的所有绑定(bind)

sharpie bind -sdk iphoneos11.1 -scope MyFramework.framework/Headers/ MyFramework.framework/Headers/MyFramework-Swift.h
-output=MyFrameworkCS -namespace=MyFramework

关于xamarin - 与目标 Sharpie 绑定(bind)会输出巨大的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47426351/

相关文章:

ios - Xamarin 表单 - IOS : How to detect the UIView size changed

c# - 使用 Xamarin/Vision 框架进行 iOS 条码检测

ios - 使用绑定(bind)项目将 native 库 libxml2 链接到 xamarin.ios 项目

c# - 目标 Sharpie 缺少大部分 API

ios - 我可以使用 Visual Studio 自动增加 Info.plist 文件中的 CFBundleVersion 值吗?

xamarin - AlarmManager 立即触发广播

ios - 购买应用内购买时应用崩溃

xamarin.ios - xamarin VisualStudio for ios 中没有附加设备

ios - 不受支持的 clang 可用性平台 : 'bridgeos'

c# - 为 UIBarButtonItem 添加/删除 EventHandler