Xamarin iOS 绑定项目
Xamarin iOS binding project
我有一个 Xamarin.iOS 应用程序,我想引用一个绑定项目,以便我可以在我的项目中使用 .a
文件。但是当我尝试构建时出现此错误:
linker command failed with exit code 1 (use -v to see invocation)
/Users/darius/Mobile-MyApp/Source/MyApp/MyApp.Touch/MTOUCH: Error MT5216: Native linking failed for '/Users/darius/Mobile-MyApp/Source/MyApp/MyApp.Touch/obj/iPhone/Debug/device-builds/iphone7.1-11.0.3/mtouch-cache/arm64/libAcrCloudSdkIosBinding.dll.dylib'. Please file a bug report at http://bugzilla.xamarin.com (MT5216) (Touchshop.Touch)
我检查了 .a
文件使用此命令行支持的架构:
xcrun -sdk iphoneos lipo -info libACRCloud_IOS_SDK.a
它输出:
Architectures in the fat file: libACRCloud_IOS_SDK.a are: armv7 i386 x86_64 arm64
我把.a
放在了NativeReferences
文件夹里。
这是我的 ApiDefinition.cs
:
using System;
using UIKit;
using Foundation;
using ObjCRuntime;
using CoreGraphics;
namespace AcrCloudSdkIos
{
// typedef void (^ACRCloudResultBlock)(NSString *, ACRCloudResultType);
delegate void ACRCloudResultBlock(string arg0, ACRCloudResultType arg1);
// typedef void (^ACRCloudResultWithFpBlock)(NSString *, NSData *);
delegate void ACRCloudResultWithFpBlock(string arg0, NSData arg1);
// typedef void (^ACRCloudStateBlock)(NSString *);
delegate void ACRCloudStateBlock(string arg0);
// typedef void (^ACRCloudVolumeBlock)(float);
delegate void ACRCloudVolumeBlock(float arg0);
// @interface ACRCloudConfig : NSObject
[BaseType(typeof(NSObject))]
interface ACRCloudConfig
{
// @property (retain, nonatomic) NSString * accessKey;
[Export("accessKey", ArgumentSemantic.Retain)]
string AccessKey { get; set; }
// @property (retain, nonatomic) NSString * accessSecret;
[Export("accessSecret", ArgumentSemantic.Retain)]
string AccessSecret { get; set; }
// @property (retain, nonatomic) NSString * host;
[Export("host", ArgumentSemantic.Retain)]
string Host { get; set; }
// @property (retain, nonatomic) NSString * audioType;
[Export("audioType", ArgumentSemantic.Retain)]
string AudioType { get; set; }
// @property (retain, nonatomic) NSString * homedir;
[Export("homedir", ArgumentSemantic.Retain)]
string Homedir { get; set; }
// @property (retain, nonatomic) NSString * uuid;
[Export("uuid", ArgumentSemantic.Retain)]
string Uuid { get; set; }
// @property (retain, nonatomic) NSString * protocol;
[Export("protocol", ArgumentSemantic.Retain)]
string Protocol { get; set; }
// @property (retain, nonatomic) NSDictionary * params;
[Export("params", ArgumentSemantic.Retain)]
NSDictionary Params { get; set; }
// @property (assign, nonatomic) ACRCloudRecMode recMode;
[Export("recMode", ArgumentSemantic.Assign)]
ACRCloudRecMode RecMode { get; set; }
// @property (assign, nonatomic) NSInteger requestTimeout;
[Export("requestTimeout")]
nint RequestTimeout { get; set; }
// @property (assign, nonatomic) NSInteger prerecorderTime;
[Export("prerecorderTime")]
nint PrerecorderTime { get; set; }
// @property (assign, nonatomic) _Bool keepPlaying;
[Export("keepPlaying")]
bool KeepPlaying { get; set; }
// @property (copy, nonatomic) ACRCloudResultBlock resultBlock;
[Export("resultBlock", ArgumentSemantic.Copy)]
ACRCloudResultBlock ResultBlock { get; set; }
// @property (copy, nonatomic) ACRCloudStateBlock stateBlock;
[Export("stateBlock", ArgumentSemantic.Copy)]
ACRCloudStateBlock StateBlock { get; set; }
// @property (copy, nonatomic) ACRCloudVolumeBlock volumeBlock;
[Export("volumeBlock", ArgumentSemantic.Copy)]
ACRCloudVolumeBlock VolumeBlock { get; set; }
// @property (copy, nonatomic) ACRCloudResultWithFpBlock resultFpBlock;
[Export("resultFpBlock", ArgumentSemantic.Copy)]
ACRCloudResultWithFpBlock ResultFpBlock { get; set; }
}
// @interface ACRCloudRecognition : NSObject
[BaseType(typeof(NSObject))]
interface ACRCloudRecognition
{
// -(id)initWithConfig:(ACRCloudConfig *)config;
[Export("initWithConfig:")]
IntPtr Constructor(ACRCloudConfig config);
// -(void)startPreRecord:(NSInteger)recordTime;
[Export("startPreRecord:")]
void StartPreRecord(nint recordTime);
// -(void)stopPreRecord;
[Export("stopPreRecord")]
void StopPreRecord();
// -(void)startRecordRec;
[Export("startRecordRec")]
void StartRecordRec();
// -(void)stopRecordRec;
[Export("stopRecordRec")]
void StopRecordRec();
// -(void)stopRecordAndRec;
[Export("stopRecordAndRec")]
void StopRecordAndRec();
// -(NSString *)recognize:(char *)buffer len:(int)len;
[Export("recognize:len:")]
unsafe string Recognize(NSObject buffer, int len);
// -(NSString *)recognize:(NSData *)pcm_data;
[Export("recognize:")]
string Recognize(NSData pcm_data);
// -(void)recognize_fp:(NSData *)fingerprint resultBlock:(ACRCloudResultBlock)resultBlock;
[Export("recognize_fp:resultBlock:")]
void Recognize_fp(NSData fingerprint, ACRCloudResultBlock resultBlock);
// -(NSString *)recognize_fp:(NSData *)fingerprint;
[Export("recognize_fp:")]
string Recognize_fp(NSData fingerprint);
// +(NSData *)get_fingerprint:(char *)pcm len:(int)len;
[Static]
[Export("get_fingerprint:len:")]
unsafe NSData Get_fingerprint(NSObject pcm, int len);
// +(NSData *)get_fingerprint:(NSData *)pcm;
[Static]
[Export("get_fingerprint:")]
NSData Get_fingerprint(NSData pcm);
// +(NSData *)get_fingerprint:(char *)pcm len:(unsigned int)len sampleRate:(unsigned int)sampleRate nChannel:(short)nChannel;
[Static]
[Export("get_fingerprint:len:sampleRate:nChannel:")]
unsafe NSData Get_fingerprint(NSObject pcm, uint len, uint sampleRate, short nChannel);
// +(NSData *)get_fingerprint:(NSData *)pcm sampleRate:(unsigned int)sampleRate nChannel:(short)nChannel;
[Static]
[Export("get_fingerprint:sampleRate:nChannel:")]
NSData Get_fingerprint(NSData pcm, uint sampleRate, short nChannel);
// +(NSData *)resample:(NSData *)pcm sampleRate:(unsigned int)sampleRate nChannel:(short)nChannel;
[Static]
[Export("resample:sampleRate:nChannel:")]
NSData Resample(NSData pcm, uint sampleRate, short nChannel);
// +(NSData *)resample:(char *)pcm len:(unsigned int)len sampleRate:(unsigned int)sampleRate nChannel:(short)nChannel;
[Static]
[Export("resample:len:sampleRate:nChannel:")]
unsafe NSData Resample(NSObject pcm, uint len, uint sampleRate, short nChannel);
// +(NSData *)resample_bit32:(char *)pcm len:(unsigned int)bytes sampleRate:(unsigned int)sampleRate nChannel:(short)nChannel isFloat:(_Bool)isFloat;
[Static]
[Export("resample_bit32:len:sampleRate:nChannel:isFloat:")]
unsafe NSData Resample_bit32(NSObject pcm, uint bytes, uint sampleRate, short nChannel, bool isFloat);
}
}
和Structs.cs
:
using System;
namespace AcrCloudSdkIosBinding
{
public enum ACRCloudRecMode : uint
{
remote = 0,
local = 1,
both = 2,
advance_remote = 3
}
public enum ACRCloudResultType
{
error = -1,
none = 0,
audio = 1,
live = 2,
audio_live = 3
}
public enum HTTPResumeType
{
error = -1,
resume = 0,
restart = 1,
success = 2
}
}
Here 是它的来源,.a
文件也可以在那里找到 (libACRCloud_IOS_SDK.a
)。
Here 是它的椰子足类。
尝试将 Xcode 和 Sharpie 更新到最新版本,然后重新创建绑定项目。
可能会有帮助。
更新:
我尝试在 official link.
之后将 Sharpie 与 cocoapods 一起使用
当我尝试绑定像AFNetworking
这样著名的第三方库时,它会生成一个名为Binding
的文件夹,在里面我们可以找到ApiDefinitions
, StructsAndEnums
和图书馆。
sharpie pod -d /Users/yourName/Desktop/FolderName init ios AFNetworking && sharpie pod -d /Users/yourName/Desktop/FolderName bind
当我尝试绑定 acrcloud
时,它没有生成绑定文件夹。
sharpie pod -d /Users/yourName/Desktop/FolderName init ios acrcloud_ios_sdk && sharpie pod -d /Users/yourName/Desktop/FolderName bind
所以我猜 acrcloud
sdk 可能有问题。
经过一周的黑客攻击,我找到了解决方案。我在 Xcode 中打开本机项目 (Swift) 的源代码,发现它引用了 libc++.tbd
。所以我所要做的就是在Visual Studio中引用.a
库的链接器标志中设置-lc++
(右键单击库->属性->链接器标志)。
此外,请确保您在 info.plist
中授予图书馆所需的适当权限。在我设置它需要的权限之前,它会在我身上崩溃而不会给出任何错误。
Cole Xia 引用的工具也值得一看,因为我不得不在生成的 ApiDefinition.cs
中手动挑选我需要的接口,因为它充满了我不需要的垃圾,并且也用它修复一些东西。所以我为此给了他赏金积分。我猜该工具不适用于该库,因为引用 libc++.tbd
.
我有一个 Xamarin.iOS 应用程序,我想引用一个绑定项目,以便我可以在我的项目中使用 .a
文件。但是当我尝试构建时出现此错误:
linker command failed with exit code 1 (use -v to see invocation) /Users/darius/Mobile-MyApp/Source/MyApp/MyApp.Touch/MTOUCH: Error MT5216: Native linking failed for '/Users/darius/Mobile-MyApp/Source/MyApp/MyApp.Touch/obj/iPhone/Debug/device-builds/iphone7.1-11.0.3/mtouch-cache/arm64/libAcrCloudSdkIosBinding.dll.dylib'. Please file a bug report at http://bugzilla.xamarin.com (MT5216) (Touchshop.Touch)
我检查了 .a
文件使用此命令行支持的架构:
xcrun -sdk iphoneos lipo -info libACRCloud_IOS_SDK.a
它输出:
Architectures in the fat file: libACRCloud_IOS_SDK.a are: armv7 i386 x86_64 arm64
我把.a
放在了NativeReferences
文件夹里。
这是我的 ApiDefinition.cs
:
using System;
using UIKit;
using Foundation;
using ObjCRuntime;
using CoreGraphics;
namespace AcrCloudSdkIos
{
// typedef void (^ACRCloudResultBlock)(NSString *, ACRCloudResultType);
delegate void ACRCloudResultBlock(string arg0, ACRCloudResultType arg1);
// typedef void (^ACRCloudResultWithFpBlock)(NSString *, NSData *);
delegate void ACRCloudResultWithFpBlock(string arg0, NSData arg1);
// typedef void (^ACRCloudStateBlock)(NSString *);
delegate void ACRCloudStateBlock(string arg0);
// typedef void (^ACRCloudVolumeBlock)(float);
delegate void ACRCloudVolumeBlock(float arg0);
// @interface ACRCloudConfig : NSObject
[BaseType(typeof(NSObject))]
interface ACRCloudConfig
{
// @property (retain, nonatomic) NSString * accessKey;
[Export("accessKey", ArgumentSemantic.Retain)]
string AccessKey { get; set; }
// @property (retain, nonatomic) NSString * accessSecret;
[Export("accessSecret", ArgumentSemantic.Retain)]
string AccessSecret { get; set; }
// @property (retain, nonatomic) NSString * host;
[Export("host", ArgumentSemantic.Retain)]
string Host { get; set; }
// @property (retain, nonatomic) NSString * audioType;
[Export("audioType", ArgumentSemantic.Retain)]
string AudioType { get; set; }
// @property (retain, nonatomic) NSString * homedir;
[Export("homedir", ArgumentSemantic.Retain)]
string Homedir { get; set; }
// @property (retain, nonatomic) NSString * uuid;
[Export("uuid", ArgumentSemantic.Retain)]
string Uuid { get; set; }
// @property (retain, nonatomic) NSString * protocol;
[Export("protocol", ArgumentSemantic.Retain)]
string Protocol { get; set; }
// @property (retain, nonatomic) NSDictionary * params;
[Export("params", ArgumentSemantic.Retain)]
NSDictionary Params { get; set; }
// @property (assign, nonatomic) ACRCloudRecMode recMode;
[Export("recMode", ArgumentSemantic.Assign)]
ACRCloudRecMode RecMode { get; set; }
// @property (assign, nonatomic) NSInteger requestTimeout;
[Export("requestTimeout")]
nint RequestTimeout { get; set; }
// @property (assign, nonatomic) NSInteger prerecorderTime;
[Export("prerecorderTime")]
nint PrerecorderTime { get; set; }
// @property (assign, nonatomic) _Bool keepPlaying;
[Export("keepPlaying")]
bool KeepPlaying { get; set; }
// @property (copy, nonatomic) ACRCloudResultBlock resultBlock;
[Export("resultBlock", ArgumentSemantic.Copy)]
ACRCloudResultBlock ResultBlock { get; set; }
// @property (copy, nonatomic) ACRCloudStateBlock stateBlock;
[Export("stateBlock", ArgumentSemantic.Copy)]
ACRCloudStateBlock StateBlock { get; set; }
// @property (copy, nonatomic) ACRCloudVolumeBlock volumeBlock;
[Export("volumeBlock", ArgumentSemantic.Copy)]
ACRCloudVolumeBlock VolumeBlock { get; set; }
// @property (copy, nonatomic) ACRCloudResultWithFpBlock resultFpBlock;
[Export("resultFpBlock", ArgumentSemantic.Copy)]
ACRCloudResultWithFpBlock ResultFpBlock { get; set; }
}
// @interface ACRCloudRecognition : NSObject
[BaseType(typeof(NSObject))]
interface ACRCloudRecognition
{
// -(id)initWithConfig:(ACRCloudConfig *)config;
[Export("initWithConfig:")]
IntPtr Constructor(ACRCloudConfig config);
// -(void)startPreRecord:(NSInteger)recordTime;
[Export("startPreRecord:")]
void StartPreRecord(nint recordTime);
// -(void)stopPreRecord;
[Export("stopPreRecord")]
void StopPreRecord();
// -(void)startRecordRec;
[Export("startRecordRec")]
void StartRecordRec();
// -(void)stopRecordRec;
[Export("stopRecordRec")]
void StopRecordRec();
// -(void)stopRecordAndRec;
[Export("stopRecordAndRec")]
void StopRecordAndRec();
// -(NSString *)recognize:(char *)buffer len:(int)len;
[Export("recognize:len:")]
unsafe string Recognize(NSObject buffer, int len);
// -(NSString *)recognize:(NSData *)pcm_data;
[Export("recognize:")]
string Recognize(NSData pcm_data);
// -(void)recognize_fp:(NSData *)fingerprint resultBlock:(ACRCloudResultBlock)resultBlock;
[Export("recognize_fp:resultBlock:")]
void Recognize_fp(NSData fingerprint, ACRCloudResultBlock resultBlock);
// -(NSString *)recognize_fp:(NSData *)fingerprint;
[Export("recognize_fp:")]
string Recognize_fp(NSData fingerprint);
// +(NSData *)get_fingerprint:(char *)pcm len:(int)len;
[Static]
[Export("get_fingerprint:len:")]
unsafe NSData Get_fingerprint(NSObject pcm, int len);
// +(NSData *)get_fingerprint:(NSData *)pcm;
[Static]
[Export("get_fingerprint:")]
NSData Get_fingerprint(NSData pcm);
// +(NSData *)get_fingerprint:(char *)pcm len:(unsigned int)len sampleRate:(unsigned int)sampleRate nChannel:(short)nChannel;
[Static]
[Export("get_fingerprint:len:sampleRate:nChannel:")]
unsafe NSData Get_fingerprint(NSObject pcm, uint len, uint sampleRate, short nChannel);
// +(NSData *)get_fingerprint:(NSData *)pcm sampleRate:(unsigned int)sampleRate nChannel:(short)nChannel;
[Static]
[Export("get_fingerprint:sampleRate:nChannel:")]
NSData Get_fingerprint(NSData pcm, uint sampleRate, short nChannel);
// +(NSData *)resample:(NSData *)pcm sampleRate:(unsigned int)sampleRate nChannel:(short)nChannel;
[Static]
[Export("resample:sampleRate:nChannel:")]
NSData Resample(NSData pcm, uint sampleRate, short nChannel);
// +(NSData *)resample:(char *)pcm len:(unsigned int)len sampleRate:(unsigned int)sampleRate nChannel:(short)nChannel;
[Static]
[Export("resample:len:sampleRate:nChannel:")]
unsafe NSData Resample(NSObject pcm, uint len, uint sampleRate, short nChannel);
// +(NSData *)resample_bit32:(char *)pcm len:(unsigned int)bytes sampleRate:(unsigned int)sampleRate nChannel:(short)nChannel isFloat:(_Bool)isFloat;
[Static]
[Export("resample_bit32:len:sampleRate:nChannel:isFloat:")]
unsafe NSData Resample_bit32(NSObject pcm, uint bytes, uint sampleRate, short nChannel, bool isFloat);
}
}
和Structs.cs
:
using System;
namespace AcrCloudSdkIosBinding
{
public enum ACRCloudRecMode : uint
{
remote = 0,
local = 1,
both = 2,
advance_remote = 3
}
public enum ACRCloudResultType
{
error = -1,
none = 0,
audio = 1,
live = 2,
audio_live = 3
}
public enum HTTPResumeType
{
error = -1,
resume = 0,
restart = 1,
success = 2
}
}
Here 是它的来源,.a
文件也可以在那里找到 (libACRCloud_IOS_SDK.a
)。
Here 是它的椰子足类。
尝试将 Xcode 和 Sharpie 更新到最新版本,然后重新创建绑定项目。
更新:
我尝试在 official link.
之后将 Sharpie 与 cocoapods 一起使用当我尝试绑定像
AFNetworking
这样著名的第三方库时,它会生成一个名为Binding
的文件夹,在里面我们可以找到ApiDefinitions
,StructsAndEnums
和图书馆。sharpie pod -d /Users/yourName/Desktop/FolderName init ios AFNetworking && sharpie pod -d /Users/yourName/Desktop/FolderName bind
当我尝试绑定
acrcloud
时,它没有生成绑定文件夹。sharpie pod -d /Users/yourName/Desktop/FolderName init ios acrcloud_ios_sdk && sharpie pod -d /Users/yourName/Desktop/FolderName bind
所以我猜 acrcloud
sdk 可能有问题。
经过一周的黑客攻击,我找到了解决方案。我在 Xcode 中打开本机项目 (Swift) 的源代码,发现它引用了 libc++.tbd
。所以我所要做的就是在Visual Studio中引用.a
库的链接器标志中设置-lc++
(右键单击库->属性->链接器标志)。
此外,请确保您在 info.plist
中授予图书馆所需的适当权限。在我设置它需要的权限之前,它会在我身上崩溃而不会给出任何错误。
Cole Xia 引用的工具也值得一看,因为我不得不在生成的 ApiDefinition.cs
中手动挑选我需要的接口,因为它充满了我不需要的垃圾,并且也用它修复一些东西。所以我为此给了他赏金积分。我猜该工具不适用于该库,因为引用 libc++.tbd
.