我用 MAUI 开发一个应用程序(仅适用于 iOS),需要使用一个用 Xamarin.iOS 编写的库,它有一个静态本机库(一个文件)
我无法使用 xamarin 项目,所以我只是创建了一个新的 maui 类库项目并将代码移动到该项目并添加了一个文件作为本机库
<ItemGroup>
<ObjcBindingNativeLibrary Include="libAreteUart\a" />
</ItemGroup>
然后我将这个类库添加到我的 maui 应用程序项目中,当我尝试构建它时,出现以下错误
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/16.2.1007/targets/Xamarin.Shared.Sdk.targets(3,3):
Error: clang++ exited with code 1:
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_ComboBarcodeApi", referenced from:
objc-class-ref in registrar.o
"_OBJC_CLASS_$_ComboNFCApi", referenced from:
objc-class-ref in registrar.o
"_OBJC_CLASS_$_ComboRFIDApi", referenced from:
objc-class-ref in registrar.o
"_OBJC_CLASS_$_CommonDevice", referenced from:
objc-class-ref in registrar.o
"_OBJC_CLASS_$_CommonReaderInfo", referenced from:
objc-class-ref in registrar.o
"_OBJC_CLASS_$_RcpApi", referenced from:
objc-class-ref in registrar.o
"_OBJC_CLASS_$_SDeviceApi", referenced from:
objc-class-ref in registrar.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation) (TestMauiApp)
据我了解,Register 属性存在问题。这是我的示例类
PS: 顺便说一句,我试过,不链接,只链接SDK和链接所有选项,但得到同样的错误
// Token: 0x02000003 RID: 3
[Register("ComboBarcodeApi", true)]
public class ComboBarcodeApi : SDeviceApi
{
// Token: 0x17000001 RID: 1
// (get) Token: 0x06000059 RID: 89 RVA: 0x0000206E File Offset: 0x0000026E
public override NativeHandle ClassHandle
{
get
{
return ComboBarcodeApi.class_ptr;
}
}
// Token: 0x0600005A RID: 90 RVA: 0x00002078 File Offset: 0x00000278
[CompilerGenerated]
[EditorBrowsable(EditorBrowsableState.Advanced)]
[Export("init")]
public ComboBarcodeApi() : base(NSObjectFlag.Empty)
{
base.IsDirectBinding = (base.GetType().Assembly == Messaging.this_assembly);
if (base.IsDirectBinding)
{
base.InitializeHandle(Messaging.IntPtr_objc_msgSend(base.Handle, Selector.GetHandle("init")), "init");
return;
}
base.InitializeHandle(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, Selector.GetHandle("init")), "init");
}
.....
}
我在这里发现了类似的问题,但没有答案或解决方法
我有一个类似的问题。我昨天刚修好。也许这对你有用。单独转到您在错误日志中看到的每个文件。在下面,
// @protocol TestViewControllerDelegate <NSObject>
[Protocol, Model(AutoGeneratedName = true)]
[BaseType(typeof(NSObject))]
interface TestViewControllerDelegate
// @protocol TestViewControllerDelegate <NSObject>
[Protocol, Model]
[BaseType(typeof(NSObject))]
interface TestViewControllerDelegate
可悲的是绑定库不会在每个文件中单独显示错误。这也意味着没有代码自动建议。因此,只需按照错误窗口中打印的内容进行操作即可。还有一些 Trail 和 error 部分。 祝你好运!