首页 > 解决方案 > Unity game not working after build (MissingMethodException)

问题描述

The game on Unity works but when I export it to Android it stops working. When I do build and run in the terminal it gives me the following error:

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

标签: c#unity3d

解决方案


这都是关于代码剥离的。如果您想要快速解决,您可以在 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>

您还可以执行更严格的代码剥离规则。有关代码剥离的更多信息,您可以通过此链接找到。


推荐阅读