ios - Xamarin - 构建绑定(bind)库 Messaging.g.cs 时出错
<p><p>在为 Xamarin.iOS 构建绑定(bind)库时遇到问题。基本上我需要构建它以将 <code>dll</code> 引用到一个单独的项目中。 </p>
<p>这是我的例子 <a href="https://www.dropbox.com/s/71bprj9d6n9hog1/SWRevealViewController-XamarinBinding-master.zip?dl=0" rel="noreferrer noopener nofollow">project</a> .</p>
<p>问题是自动生成的 <code>Messaging.g.cs</code> 出现错误并在中线完成:</p>
<pre><code>//
// 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";
public extern static IntPtr IntPtr_objc_msgSend (IntPtr receiever, IntPtr selector);
public extern static IntPtr IntPtr_objc_msgSendSuper (IntPtr receiever, IntPtr selector);
public extern static IntPtr IntPtr_objc_msgSend_IntPtr (IntPtr receiever, IntPtr selector, IntPtr arg1);
public extern static IntPtr IntPtr_objc_msgSendSuper_IntPtr (IntPtr receiever, IntPtr selector, IntPtr arg1);
public extern static void void_objc_msgSend_IntPtr (IntPtr receiver, IntPtr selector, IntPtr arg1);
public extern static void void_objc_msgSendSuper_IntPtr (IntPtr receiver, IntPtr selector, IntPtr arg1);
public extern static int int_objc_msgSend (IntPtr receiver, IntPtr selector);
public extern static int int_objc_msgSendSuper (IntPtr receiver, IntPtr selector);
public extern static void void_objc_msgSend_int (IntPtr receiver, IntPtr selector, int arg1);
public extern static void void_objc_msgSendSuper_int (IntPtr receiver, IntPtr selector, int arg1);
public extern static float float_objc_msgSend (IntPtr receiver, IntPtr selector);
public extern static float float_objc_msgSendSuper (IntPtr receiver, IntPtr selector);
public extern static void void_objc_msgSend_float (IntPtr receiver, IntPtr selector, float arg1);
public extern static void void_objc_msgSendSuper_float (IntPtr receiver, IntPtr selector, float arg1);
public extern static bool bool_objc_msgSend (IntPtr receiver, IntPtr selector);
public extern static bool bool_objc_msgSendSuper (IntPtr receiver, IntPtr selector);
public extern static void void_objc_msgSend_bool (IntPtr receiver, IntPtr selector, bool arg1);
public extern static void void_objc_msgSendSuper_bool (IntPtr receiver, IntPtr selector, bool arg1);
public extern static global::System.Double Double_objc_msgSend (IntPtr receiver, IntPtr selector);
public extern static global::System.Double Double_objc_msgSendSuper (IntPtr receiver, IntPtr selector);
public extern static void vo
</code></pre>
<p>我也关注了来自 <a href="https://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/" rel="noreferrer noopener nofollow">Xamarin</a> 的官方 walktrough .</p>
<p>我正在尝试构建的项目的原始存储库是 <a href="https://github.com/Vandborg/SWRevealViewController-XamarinBinding" rel="noreferrer noopener nofollow">here</a>这是原始 Objectice-C 的绑定(bind)项目 <a href="https://github.com/John-Lluch/SWRevealViewController" rel="noreferrer noopener nofollow">here</a> .</p>
<p>我不明白为什么 <code>Messaging.g.cs</code> 会出错并阻止构建完成。</p>
<p>如有任何帮助,我们将不胜感激。</p>
<p>祝一切顺利</p>
<p>约翰</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我已经设法解决了这个问题。 </p>
<p>我希望这个答案对以后的其他 Xamarin 开发人员有所帮助。 </p>
<p>如果您使用的是 Objective C 绑定(bind)库,则应使用 XCode 构建并使用可用的 <code>Objective Sharpie</code> 生成 ApiDefinition.cs 和 StructsAndEnums.cs <a href="https://developer.xamarin.com/guides/cross-platform/macios/binding/objective-sharpie/getting-started/" rel="noreferrer noopener nofollow">here</a> .</p>
<p>我遇到的问题是自动生成的代码无法正确处理 <code>Delegates</code>。此外,<code></code> 属性导致解释器使用不兼容的数据类型 - 即 <code>enum</code> 结构与 <code>uint</code>。 </p>
<p>综合上述问题,我还试图在同一个项目中绑定(bind)多个 <code>.a</code> 静态库。 </p>
<p>因此,您需要在 Objective Sharpie 生成的 C# 文件中重构一些内容:</p>
<p>删除方法签名的任何重复在我的示例中,该工具生成了以下代码:</p>
<pre><code> // @optional -(BOOL)revealControllerPanGestureShouldBegin:(SWRevealViewController *)revealController;
bool RevealController(SWRevealViewController revealController);
// @optional -(BOOL)revealControllerTapGestureShouldBegin:(SWRevealViewController *)revealController;
bool RevealController(SWRevealViewController revealController);
</code></pre>
<p>为了避免编译器抛出重复的方法错误,它应该是:</p>
<pre><code> // @optional -(BOOL)revealControllerPanGestureShouldBegin:(SWRevealViewController *)revealController;
bool RevealControllerPanGestureShouldBegin(SWRevealViewController revealController);
// @optional -(BOOL)revealControllerTapGestureShouldBegin:(SWRevealViewController *)revealController;
bool RevealControllerTapGestureShouldBegin(SWRevealViewController revealController);
</code></pre>
<p>接下来,找到任何示例,其中工具已生成继承自不受支持的原语的枚举结构。 </p>
<p>所以,例如:</p>
<pre><code>
public enum FrontViewPosition : uint
{
LeftSideMostRemoved,
LeftSideMost,
LeftSide,
Left,
Right,
RightMost,
RightMostRemoved
}
</code></pre>
<p>对 <code>public enum FrontViewPosition : ulong</code> 的更改。</p>
<p>接下来移除任何<code></code>装饰。</p>
<p>最后,我发现 Objective Sharpie 对扩展方法的处理很差,导致生成的代码试图创建一个内部有虚拟方法的静态类......</p>
<p>要修复,请找到 <code></code> 的所有实例,例如:</p>
<pre><code>// @interface SWRevealViewController (UIViewController)
partial interface UIViewController_SWRevealViewController
{
// -(SWRevealViewController *)revealViewController;
SWRevealViewController RevealViewController{ get; };
}
</code></pre>
<p>并将其更改为</p>
<pre><code>// @interface SWRevealViewController (UIViewController)
partial interface UIViewController_SWRevealViewController
{
// -(SWRevealViewController *)revealViewController;
SWRevealViewController RevealViewController();
}
</code></pre>
<p>现在清理并重建,自动生成的代码现在可以正确编译。在任何需要的项目中引用绑定(bind) dll 以使用它。 </p>
<p>如果有人想在 Xamarin 中使用 <code>SWRevealViewController</code> 库,那么为了节省您的时间,您可以使用我的存储库 <a href="https://github.com/saluton-mundo/SWRevealViewController" rel="noreferrer noopener nofollow">here</a> .</p>
<p>祝你好运,玩得开心。</p>
<p>约翰</p></p>
<p style="font-size: 20px;">关于ios - Xamarin - 构建绑定(bind)库 Messaging.g.cs 时出错,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37461923/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37461923/
</a>
</p>
页:
[1]