Unity 问题之 打包真机运行报错 MissingMethodException: Default constructor not found for type xxxxxx 问题处理

Unity 问题之 打包真机运行报错 MissingMethodException: Default constructor not found for type xxxxxx 问题处理

目录

Unity 问题之 打包真机运行报错 MissingMethodException: Default constructor not found for type xxxxxx 问题处理

一、简单介绍

二、问题现象

三、解决方式


一、简单介绍

Unity 在开发中,记录一些报错问题,以便后期遇到同样问题处理。

二、问题现象

1、可能大家会遇到类似 System.MissingMethodException: Default constructor not found for type XXFramework.AssetModule.AssetModule 报错

2、或者类似如下的报错

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

三、解决方式

1、快速解决方式可以根据对应的添加,可以在 Assets 文件夹中创建 link.xml 文件

第一个是

<linker>
  <assembly fullname="XXFramework">
    <type fullname="XXFramework.AssetModule.AssetModule" preserve="all" />
    <!-- 添加其他需要保留的类型或方法 -->
  </assembly>
</linker>

第二个是

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

2、不过如果添加了如上的代码,还是不行的话,可能还需要给对应的类添加一个默认的无参构造函数

例如:

namespace XXFramework.AssetModule{

    public class AssetModule{
        private string m_Test;
        public AssetModule(){
            m_Test = "";
        }
    }

}

3、如果有太多的 MissingMethodException: Default constructor not found for type 报错,可以尝试如下的方式

<linker>
  <assembly fullname="XXFramework, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" preserve="all">
    <!--assembly fullname="XXFramework"-->
    <type fullname="XXFramework.AssetModule.AssetModule" preserve="all" />
    <!-- 添加其他需要保留的类型或方法 -->
  </assembly>
</linker>

更多 Unity link 相关信息(代码剥离的信息)可参见:Unity - Manual: Managed code stripping

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

仙魁XAN

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值