![](/img/trans.png)
[英]Weird Xamarin.iOS bug only with Enable debug on (adhoc/release builds)
[英]Xamarin.iOS builds, most notably Linking and AOT-compilation, take over 2 minutes in debug configurations
我有一个 Xamarin.iOS 项目(作为跨平台解决方案的一部分),随着时间的推移它已经增长了很多。 然而,只有 iOS 构建花费了如此多的时间(Windows 桌面构建需要几秒钟,而 Android 很少超过 30 秒,其中 24 秒是安装过程)。 经过大量调整后,我可以将 iOS 设备/模拟器的构建时间减少到大约 02:21,这仍然远远不利于调试。
下面是这次实现的工程文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-ios</TargetFramework>
<SingleProject>true</SingleProject>
<OutputType>Exe</OutputType>
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
<IsUnoHead>true</IsUnoHead>
<SupportedOSPlatformVersion>14.2</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<UseMauiEssentials>True</UseMauiEssentials>
<ProvisioningType>manual</ProvisioningType>
<MtouchInterpreter>-all</MtouchInterpreter>
</PropertyGroup>
<PropertyGroup>
<MtouchExtraArgs>$(MtouchExtraArgs) --setenv=MONO_GC_PARAMS=soft-heap-limit=512m,nursery-size=64m,evacuation-threshold=66,major=marksweep,concurrent-sweep</MtouchExtraArgs>
<MtouchExtraArgs>$(MtouchExtraArgs) --marshal-objectivec-exceptions:disable</MtouchExtraArgs>
<MtouchExtraArgs>$(MtouchExtraArgs) --marshal-managed-exceptions:default</MtouchExtraArgs>
<MtouchExtraArgs>$(MtouchExtraArgs) --registrar:static</MtouchExtraArgs>
<MtouchExtraArgs>$(MtouchExtraArgs) --time --time</MtouchExtraArgs>
<MtouchExtraArgs>$(MtouchExtraArgs) -v -v -v -v</MtouchExtraArgs>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<MtouchLink>Full</MtouchLink>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' != 'Debug'">
<MtouchUseLlvm>true</MtouchUseLlvm>
<MtouchLink>SdkOnly</MtouchLink>
<BuildIpa>true</BuildIpa>
<Optimize>true</Optimize>
<CodesignKey>***</CodesignKey>
<CodesignProvision>***</CodesignProvision>
</PropertyGroup>
<ItemGroup>
<!--project references-->
</ItemGroup>
</Project>
环境:
不过,在其中任何一个的各自较旧版本上,该问题既没有变坏也没有变好。
与通过 Visual Studio 远程构建相比,直接从 Mac 构建没有显着改进。
我尝试篡改一些项目属性以尽可能缩短构建时间:
MtouchLink
Failed to AOT compile Microsoft.iOS.dll, the AOT compiler exited with code 134
错误。MtouchInterpreter
MtouchUseLlvm
省略部分或全部MtouchExtraArgs
也无济于事。
有一些任务占用了大部分时间到 binlog:
Xamarin.iOS 默认使用 AOT :Apple 设置了 iOS 的安全限制,不允许在设备上执行动态生成的代码。 为确保我们遵守这些安全协议,Xamarin.iOS 使用提前 (AOT) 编译器来编译托管代码。
AOT 编译是一种用于提高启动性能的优化技术,但它也会影响应用程序的构建时间。 Xamarin AOT文档中介绍:
构建时间——AOT 编译比 JIT 慢得多,并且会减慢使用它的构建。 这种减慢的范围从几秒到一分钟或更长时间,具体取决于编译的程序集的大小和数量。
链接 Xamarin.iOS Apps 文档描述(这也是构建时间更长的原因):
linker 使用 static 分析来确定您的应用程序可接受遵循的不同代码路径。 它有点重,因为它必须 go 通过每个组件的每个细节,以确保没有删除任何可发现的内容。 它在模拟器构建中默认不启用,以在调试时加快构建时间。
您可以尝试关闭 Visual Studio,然后从您的项目中删除 bin 和 obj,这将缓解构建缓慢的问题。 更多信息可以参考: iOS Build Mechanics
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.