首页 > 解决方案 > Unity 项目仅适用于 IL2CPP 上的 Development Build

问题描述

我有一个移动应用程序项目,它在 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- ios.731471 上的传输库/

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

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

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

我还在 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>

标签: c#androidiosxcodeunity3d

解决方案


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

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

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

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

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

推荐阅读