在为 Xamarin.iOS 构建绑定(bind)库时遇到问题。基本上我需要构建它以将 dll
引用到一个单独的项目中。
这是我的例子 project .
问题是自动生成的 Messaging.g.cs
出现错误并在中线完成:
//
// Auto-generated from generator.cs, do not edit
//
// We keep references to objects, so warning 414 is expected
#pragma warning disable 414
using System;
using System.Drawing;
using System.Diagnostics;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using UIKit;
using GLKit;
using Metal;
using MapKit;
using ModelIO;
using Security;
using SceneKit;
using CoreVideo;
using CoreMedia;
using QuickLook;
using Foundation;
using CoreMotion;
using ObjCRuntime;
using AddressBook;
using CoreGraphics;
using CoreLocation;
using AVFoundation;
using NewsstandKit;
using CoreAnimation;
using CoreFoundation;
namespace ApiDefinition {
partial class Messaging {
static internal System.Reflection.Assembly this_assembly = typeof (Messaging).Assembly;
const string LIBOBJC_DYLIB = "/usr/lib/libobjc.dylib";
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSend")]
public extern static IntPtr IntPtr_objc_msgSend (IntPtr receiever, IntPtr selector);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSendSuper")]
public extern static IntPtr IntPtr_objc_msgSendSuper (IntPtr receiever, IntPtr selector);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSend")]
public extern static IntPtr IntPtr_objc_msgSend_IntPtr (IntPtr receiever, IntPtr selector, IntPtr arg1);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSendSuper")]
public extern static IntPtr IntPtr_objc_msgSendSuper_IntPtr (IntPtr receiever, IntPtr selector, IntPtr arg1);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSend")]
public extern static void void_objc_msgSend_IntPtr (IntPtr receiver, IntPtr selector, IntPtr arg1);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSendSuper")]
public extern static void void_objc_msgSendSuper_IntPtr (IntPtr receiver, IntPtr selector, IntPtr arg1);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSend")]
public extern static int int_objc_msgSend (IntPtr receiver, IntPtr selector);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSendSuper")]
public extern static int int_objc_msgSendSuper (IntPtr receiver, IntPtr selector);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSend")]
public extern static void void_objc_msgSend_int (IntPtr receiver, IntPtr selector, int arg1);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSendSuper")]
public extern static void void_objc_msgSendSuper_int (IntPtr receiver, IntPtr selector, int arg1);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSend")]
public extern static float float_objc_msgSend (IntPtr receiver, IntPtr selector);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSendSuper")]
public extern static float float_objc_msgSendSuper (IntPtr receiver, IntPtr selector);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSend")]
public extern static void void_objc_msgSend_float (IntPtr receiver, IntPtr selector, float arg1);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSendSuper")]
public extern static void void_objc_msgSendSuper_float (IntPtr receiver, IntPtr selector, float arg1);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSend")]
public extern static bool bool_objc_msgSend (IntPtr receiver, IntPtr selector);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSendSuper")]
public extern static bool bool_objc_msgSendSuper (IntPtr receiver, IntPtr selector);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSend")]
public extern static void void_objc_msgSend_bool (IntPtr receiver, IntPtr selector, bool arg1);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSendSuper")]
public extern static void void_objc_msgSendSuper_bool (IntPtr receiver, IntPtr selector, bool arg1);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSend")]
public extern static global::System.Double Double_objc_msgSend (IntPtr receiver, IntPtr selector);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSendSuper")]
public extern static global::System.Double Double_objc_msgSendSuper (IntPtr receiver, IntPtr selector);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSend")]
public extern static void vo
我也关注了来自 Xamarin 的官方 walktrough .
我正在尝试构建的项目的原始存储库是 here这是原始 Objectice-C 的绑定(bind)项目 here .
我不明白为什么 Messaging.g.cs
会出错并阻止构建完成。
如有任何帮助,我们将不胜感激。
祝一切顺利
约翰
我已经设法解决了这个问题。
我希望这个答案对以后的其他 Xamarin 开发人员有所帮助。
如果您使用的是 Objective C 绑定(bind)库,则应使用 XCode 构建并使用可用的 Objective Sharpie
生成 ApiDefinition.cs 和 StructsAndEnums.cs here .
我遇到的问题是自动生成的代码无法正确处理 Delegates
。此外,[Native]
属性导致解释器使用不兼容的数据类型 - 即 enum
结构与 uint
。
综合上述问题,我还试图在同一个项目中绑定(bind)多个 .a
静态库。
因此,您需要在 Objective Sharpie 生成的 C# 文件中重构一些内容:
删除方法签名的任何重复在我的示例中,该工具生成了以下代码:
// @optional -(BOOL)revealControllerPanGestureShouldBeginSWRevealViewController *)revealController;
[Export("revealControllerPanGestureShouldBegin:")]
bool RevealController(SWRevealViewController revealController);
// @optional -(BOOL)revealControllerTapGestureShouldBeginSWRevealViewController *)revealController;
[Export("revealControllerTapGestureShouldBegin:")]
bool RevealController(SWRevealViewController revealController);
为了避免编译器抛出重复的方法错误,它应该是:
// @optional -(BOOL)revealControllerPanGestureShouldBeginSWRevealViewController *)revealController;
[Export("revealControllerPanGestureShouldBegin:")]
bool RevealControllerPanGestureShouldBegin(SWRevealViewController revealController);
// @optional -(BOOL)revealControllerTapGestureShouldBeginSWRevealViewController *)revealController;
[Export("revealControllerTapGestureShouldBegin:")]
bool RevealControllerTapGestureShouldBegin(SWRevealViewController revealController);
接下来,找到任何示例,其中工具已生成继承自不受支持的原语的枚举结构。
所以,例如:
[Native]
public enum FrontViewPosition : uint
{
LeftSideMostRemoved,
LeftSideMost,
LeftSide,
Left,
Right,
RightMost,
RightMostRemoved
}
对 public enum FrontViewPosition : ulong
的更改。
接下来移除任何[Verify]
装饰。
最后,我发现 Objective Sharpie 对扩展方法的处理很差,导致生成的代码试图创建一个内部有虚拟方法的静态类......
要修复,请找到 [Category]
的所有实例,例如:
// @interface SWRevealViewController (UIViewController)
[Category]
[BaseType(typeof(UIViewController))]
partial interface UIViewController_SWRevealViewController
{
// -(SWRevealViewController *)revealViewController;
[Export("revealViewController")]
SWRevealViewController RevealViewController{ get; };
}
并将其更改为
// @interface SWRevealViewController (UIViewController)
[Category]
[BaseType(typeof(UIViewController))]
partial interface UIViewController_SWRevealViewController
{
// -(SWRevealViewController *)revealViewController;
[Export("revealViewController")]
SWRevealViewController RevealViewController();
}
现在清理并重建,自动生成的代码现在可以正确编译。在任何需要的项目中引用绑定(bind) dll 以使用它。
如果有人想在 Xamarin 中使用 SWRevealViewController
库,那么为了节省您的时间,您可以使用我的存储库 here .
祝你好运,玩得开心。
约翰
关于ios - Xamarin - 构建绑定(bind)库 Messaging.g.cs 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37461923/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |