You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

迁移Xamarin iOS绑定库到.NET MAUI 8.0时出现arm64未定义符号错误

问题描述

将Xamarin框架迁移到.NET MAUI 8.0时,使用JetBrains Rider创建了绑定库的ApiDefinitions.cs和StructsAndEnums.cs文件,添加.xcframework文件夹后成功编译生成.dll,但构建iOS测试MAUI应用时出现编译错误:

Xamarin.Shared.Sdk.targets(1648,3): Error : clang++ exited with code 1:

Undefined symbols for architecture arm64:

"OBJC_CLASS$_ACTION", referenced from:

错误日志中还有更多未定义符号提示,绑定库的.csproj配置如下:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net8.0-ios</TargetFramework>
        <ForceSimulatorX64ArchitectureInIDE>true</ForceSimulatorX64ArchitectureInIDE>
        <OutputType>Library</OutputType>
        <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
        <EnableDefaultItems>false</EnableDefaultItems>
        <ObjcBindingMode>Native</ObjcBindingMode>
        <BindingProjectType>Native</BindingProjectType>
        <IncludeSymbols>true</IncludeSymbols>
        <IncludeNativeSymbols>true</IncludeNativeSymbols>
        <Nullable>enable</Nullable>
        <ImplicitUsings>true</ImplicitUsings>
        <IsBindingProject>true</IsBindingProject>
    </PropertyGroup>
    <PropertyGroup>
      <SupportedArchitectures>arm64;x86_64</SupportedArchitectures>
    </PropertyGroup>

    <ItemGroup>
        <ObjcBindingApiDefinition Include="ApiDefinition.cs"/>
        <ObjcBindingCoreSource Include="StructsAndEnums.cs"/>
    </ItemGroup>

    <ItemGroup>
      <Folder Include="Frameworks\" />
    </ItemGroup>

    <ItemGroup>
      <NativeReference Include="Frameworks/CustomFramework.xcframework">
        <Kind>Framework</Kind>
        <SmartLink>false</SmartLink>
        <ForceLoad>true</ForceLoad>
        <LinkerFlags>-ObjC</LinkerFlags>
      </NativeReference>
  </ItemGroup>

</Project>
可能的原因及解决方向
  • .xcframework架构不匹配
    检查CustomFramework.xcframework是否包含当前构建目标的架构(arm64对应真机,x86_64对应模拟器)。终端执行以下命令查看:

    xcrun lipo -info Frameworks/CustomFramework.xcframework/ios-arm64/CustomFramework.framework/CustomFramework
    

    若缺少对应架构,需重新获取包含所需架构的.xcframework文件。

  • 绑定库未正确链接到测试应用
    确保MAUI测试应用项目已正确引用绑定库的.dll文件,且Copy Local属性设为True;同时检查测试应用的.csproj是否包含绑定库引用:

    <ItemGroup>
      <ProjectReference Include="..\YourBindingLibrary\YourBindingLibrary.csproj" />
    </ItemGroup>
    
  • ApiDefinitions.cs绑定错误
    确认ApiDefinitions.cs中对ACTION类的绑定与原生.framework中的类完全一致,类名、命名空间不能有误。示例正确绑定:

    [BaseType(typeof(NSObject))]
    interface ACTION
    {
        // 对应原生类的方法/属性绑定
    }
    
  • 链接器标志配置优化
    尝试在NativeReference的LinkerFlags中添加-all_load强制加载所有符号(注意会增加包体积):

    <LinkerFlags>-ObjC -all_load</LinkerFlags>
    
  • 清理构建缓存
    删除绑定库和测试应用的bin、obj文件夹,执行Clean Solution后重新编译。

  • 缺失原生依赖框架
    检查CustomFramework.xcframework是否依赖其他系统框架,若有需在绑定库.csproj中添加引用:

    <ItemGroup>
      <AdditionalFramework Include="Foundation" />
      <AdditionalFramework Include="UIKit" />
      <!-- 添加其他依赖的系统框架 -->
    </ItemGroup>
    

内容的提问来源于stack exchange,提问作者NPRKF

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 20:14:51