Unity游戏编译后无法运行(MissingMethodException)

5
Unity上的游戏可以运行,但在我将其导出到Android后就无法正常工作。在终端上进行“构建和运行”时会提示以下错误:
2020/10/30 14:09:09.050 20499 20540 Error Unity MissingMethodException: Default constructor not found for type UnityEngine.ResourceManagement.AsyncOperations.ProviderOperation`1[[UnityEngine.AddressableAssets.Initialization.ResourceManagerRuntimeData, Unity.Addressables, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]
2020/10/30 14:09:09.050 20499 20540 Error Unity   at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0 
2020/10/30 14:09:09.050 20499 20540 Error Unity   at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0 
2020/10/30 14:09:09.050 20499 20540 Error Unity   at UnityEngine.ResourceManagement.Util.LRUCacheAllocationStrategy.New (System.Type type, System.Int32 typeHash) [0x00000] in <00000000000000000000000000000000>:0 
2020/10/30 14:09:09.050 20499 20540 Error Unity   at UnityEngine.ResourceManagement.ResourceManager.CreateOperation[T] (System.Type actualType, System.Int32 typeHash, System.Int32 operationHash, System.Action`1[T] onDestroyAction) [0x00000] in <00000000000000000000000000000000>:0 
2020/10/30 14:09:09.050 20499 20540 Error Unity   at UnityEngine.ResourceManagement.ResourceManager.ProvideResource (UnityEngine.ResourceM
2020/10/30 14:09:09.057 20499 20540 Error Unity MissingMethodException: Default constructor not found for type UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[[System.Collections.Generic.IList`1[[ThemeData, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
2020/10/30 14:09:09.057 20499 20540 Error Unity   at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0 
2020/10/30 14:09:09.057 20499 20540 Error Unity   at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0 
2020/10/30 14:09:09.057 20499 20540 Error Unity   at UnityEngine.ResourceManagement.Util.LRUCacheAllocationStrategy.New (System.Type type, System.Int32 typeHash) [0x00000] in <00000000000000000000000000000000>:0 
2020/10/30 14:09:09.057 20499 20540 Error Unity   at UnityEngine.ResourceManagement.ResourceManager.CreateOperation[T] (System.Type actualType, System.Int32 typeHash, System.Int32 operationHash, System.Action`1[T] onDestroyAction) [0x00000] in <00000000000000000000000000000000>:0 
2020/10/30 14:09:09.057 20499 20540 Error Unity   at UnityEngine.ResourceManagement.Res

你是否拥有最新的Android操作系统?我查找了类似的问题,发现早在2019年就有了一个解决方法,所以我怀疑你可能正在使用旧版的Android。 - jdweng
Android 运行在手机/设备内核之上,而内核可能会比较老旧。 - jdweng
你最终解决了这个问题吗? - andygeers
我也遇到了同样的问题:( - hk1ll3r
我也有同样的问题 :/ Unity 2020.3.33f1 & 2021.2.19f1 - Alerr
显示剩余3条评论
2个回答

5

这与代码剥离有关。如果您想要快速解决问题,则可以在Assets文件夹中创建link.xml文件,并将其内容设置为:

<linker>
    <assembly fullname="Unity.ResourceManager" preserve="all" />
    <assembly fullname="Unity.Addressables" preserve="all" />
</linker>

如果你不使用 Addressables,下面是代码:

<linker>
    <assembly fullname="Unity.ResourceManager" preserve="all" />
</linker>

此外,您可以实行更严格的代码剥离规则。有关代码剥离的更多信息,请查看此链接


0

如果您发现本地化包在构建中无法正常工作,请尝试以下操作:

  1. 更新到最新的Unity补丁版本
  2. 在包管理器中更新到最新的可寻址资产包。
  3. 尝试禁用代码剥离
  4. 清理并重新构建地址。在构建时,请确保编辑器已设置为构建设置窗口中的目标平台。
  5. 尝试运行本地化分析器(0.11.0-preview)。这可以在Addressables窗口中找到。 链接

参考

https://forum.unity.com/threads/troubleshooting-addressables-issues.1060346/

1


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接