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

MAUI(.NET8)Android Release构建报错:调试正常但关联iOS Firebase包

.NET8 MAUI Android Release构建时误引入iOS Firebase包导致文件复制错误

问题现象

为仅支持iOS和Android的.NET8 MAUI项目集成Firebase推送通知后,调试阶段物理设备运行正常,但构建Android Release安装包时出现220个文件复制错误,所有错误均指向仅适用于iOS的NuGet包xamarin.firebase.ios.cloudfirestore,这些文件本不应参与Android构建流程。

错误示例:

1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\arm64\Microsoft.Common.CurrentVersion.targets(4911,5): error MSB3030: Could not copy the file "C:\Users\mwa\.nuget\packages\xamarin.firebase.ios.cloudfirestore\8.10.0.3\lib\net6.0-ios15.4\Firebase.CloudFirestore.resources\grpc.xcframework\ios-arm64\grpc.framework\PrivateHeaders\src\core\tsi\alts\zero_copy_frame_protector\alts_grpc_record_protocol_common.h" because it was not found.
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\arm64\Microsoft.Common.CurrentVersion.targets(4911,5): error MSB3030: Could not copy the file "C:\Users\mwa\.nuget\packages\xamarin.firebase.ios.cloudfirestore\8.10.0.3\lib\net6.0-ios15.4\Firebase.CloudFirestore.resources\grpc.xcframework\ios-arm64_x86_64-simulator\grpc.framework\PrivateHeaders\src\core\ext\filters\client_channel\client_channel_channelz.h" because it was not found.

可能原因及解决方法

1. 依赖传递导致跨平台引用

该iOS专属包可能通过其他NuGet包间接引入到Android构建中,需明确限定其仅在iOS平台生效:
在项目的.csproj文件中,找到对应包的引用(若为间接引用,可手动添加带条件的引用覆盖):

<PackageReference Include="xamarin.firebase.ios.cloudfirestore" Version="8.10.0.3" Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'" />

若为间接依赖,可通过PrivateAssets阻止其传递到Android:

<PackageReference Include="依赖该iOS包的父包" Version="x.x.x">
  <PrivateAssets>all</PrivateAssets>
</PackageReference>

2. NuGet缓存或构建残留问题

清理本地NuGet缓存并重新还原依赖:
打开终端运行:

dotnet nuget locals all --clear

然后在Visual Studio中执行清理解决方案→删除bin/obj文件夹→还原NuGet包→重新构建。

3. MSBuild配置错误包含iOS资源

检查项目.csproj或自定义.targets文件,确保没有跨平台的资源复制任务。添加条件排除Android构建时的iOS专属资源:

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'ios'">
  <None Remove="**\Firebase.CloudFirestore.resources\**" />
  <Content Remove="**\Firebase.CloudFirestore.resources\**" />
</ItemGroup>

4. 升级兼容.NET8 MAUI的Firebase包

旧版本的Xamarin Firebase包可能存在.NET MAUI跨平台适配问题,尝试将所有Firebase相关包升级到支持.NET8 MAUI的最新版本,替换为MAUI专用的Firebase NuGet包(避免使用仅Xamarin.iOS的包)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 09:00:09