Unity 项目仅适用于基于 IL2CPP 的开发构建

时间:2021-05-13 07:28:24

标签: c# android ios xcode unity3d

我有一个移动应用程序项目,它在 Android 上构建流畅且没有任何错误。但是当我尝试将它构建到 iOS 设备时,我在 Xcode 中收到此错误:

Unable to find internal function `UnityEngine.Jobs.TransformAccess::GetWorldToLocalMatrix`
Unity.Burst.BurstCompilerHelper:IsCompiledByBurst(Delegate)
Unity.Burst.BurstCompilerHelper:.cctor()
Unity.Burst.BurstCompiler:Compile(T, Boolean)
Unity.Entities.ComponentSystemGroup:.cctor()
Unity.Entities.InitializationSystemGroup:.ctor()
System.Reflection.MonoCMethod:InternalInvoke(Object, Object[])
System.Activator:CreateInstance(Type, Boolean)
Unity.Entities.TypeManager:ConstructSystem(Type)
Unity.Entities.World:CreateSystemInternal(Type)
Unity.Entities.World:GetOrCreateSystem()
Unity.Entities.DefaultWorldInitialization:AddSystemToRootLevelSystemGroupsInternal(World, IEnumerable`1, Int32)
Unity.Entities.DefaultWorldInitialization:Initialize(String, Boolean)
Unity.Entities.AutomaticWorldBootstrap:Initialize()

Unity 把项目建到 Xcode 就好了,而且 Xcode 好像也把项目建到了设备上,但是在设备上运行的时候,就抛出这个错误,崩溃了。。。我试着在上面查找不同的解决方案互联网,我找到了一些链接,但到目前为止这些链接都不起作用:

https://forum.unity.com/threads/solved-unable-to-find-internal-function.777044/ https://forum.unity.com/threads/unable-to-find-internal-function-with-transport-library-on-ios.731471/

知道什么可能导致此错误吗?顺便说一句,我正在使用 Unity 2020.2.1f1

编辑 |更新 如果我在启用“开发构建”的情况下构建项目,它会在 IL2CPP Android 和 iOS 上正常运行。但是如果我取消选中 Development Build,它会像以前一样在 Android 和 iOS IL2CPP 版本上崩溃。奇怪的。任何可能的信息?在 Android 上的 Mono 上构建相同的项目也很顺利...... 对我来说看起来像是代码剥离错误,我尝试了以下解决方案:

  • 禁用剥离引擎代码
  • 更新 Jobs 和 Burst 包
  • 启用/禁用突发编译

到目前为止,这些都没有奏效。 :(

我还在assets文件夹中添加了一个link.xml文件,看起来像这样

    <linker>
  <assembly fullname="Unity.Collections" preserve="all" />
  <assembly fullname="Unity.Collections.Tests" preserve="all" />
  <assembly fullname="Unity.Burst.Tests" preserve="all" />
  <assembly fullname="Unity.Transforms" preserve="all" />
  <assembly fullname="Unity.Transforms.Hybrid" preserve="all" />
  <assembly fullname="Unity.Transforms.Tests" preserve="all" />
  <assembly fullname="Unity.Jobs" preserve="all" />
  <assembly fullname="Unity.Jobs.Tests" preserve="all" />
  <assembly fullname="Unity.Burst" preserve="all" />
  <assembly fullname="UnityEngine">
         <type fullname="UnityEngine.*" preserve="all"/>
         <type fullname="UnityEngine.Jobs.*" preserve="all"/>
         <type fullname="UnityEngine.Jobs.TransformAccess.*" preserve="all"/>
  </assembly>
</linker>

1 个答案:

答案 0 :(得分:0)

经过将近一周的努力和大量调试后,我发现了问题。简而言之,崩溃是由 Unity.Entities 0.17.0-preview.41 包引起的。 (参考https://docs.unity3d.com/Packages/com.unity.entities@0.17/manual/index.html

即使在 IL2CPP 脚本后端构建空项目 + 开发构建未选中并且安装了上述实体预览包,应用程序也会崩溃,您可能会遇到与我相同的错误。

我不知道这到底是不是代码剥离错误,但我发现了一件奇怪的事情,如果启用了实体预览包,它会排在脚本执行顺序的第一个位置(您可以在项目设置中查看)和也许这导致了缺少 Internal 函数的问题。 (因为 Entities 包依赖于 UnityEngine.Jobs.TransformAccess 但当 Entities 包首先执行时,它还找不到工作,这是我背后的逻辑,但如果我错了,请纠正我)

我仍然不确定为什么我首先安装了那个包,因为我什至没有在这个项目中使用它,所以删除它解决了我的所有问题,项目现在运行顺利。也许这会对将来有类似问题的人有所帮助。我只能说结论是:

  1. 小心预览包。
  2. 在解决此问题之前不要使用 Unity.Entities 预览包。