unity Could not produce class with ID
PC运行正常,真机崩溃
以安卓手机为例,adb调试查找崩溃原因,显示Could not produce class with ID xxx。
以下是一段日志:
// A code block
04-13 19:47:29.360: E/Unity(8326): Could not produce class with ID 331.
04-13 19:47:29.360: E/Unity(8326): This could be caused by a class being stripped from
the build even though it is needed. Try disabling 'Strip Engine Code' in Player Settings.
以上提到代码被裁切了。
打开unity设置查看是否开启了代码裁切功能
发现项目中确实开启了。但是不开启会使打包的包体变大。
解决方案:
- 去掉勾选重新打包
- 在项目的Assets目录下新建一个名为link.xml的文件。
<linker>
<assembly fullname="UnityEngine">
<type fullname="UnityEngine.ParticleSystem" preserve="all"/>
<type fullname="UnityEngine.className1" preserve="all"/>
<type fullname="UnityEngine.className2" preserve="all"/>
</assembly>
</linker>
把缺失ID对应的类库添加到link.xml文件中重新打包问题就解决了。
下面是unity官方给出的对照表:
https://docs.unity3d.com/Manual/ClassIDReference.html
链接: id对应类库链接,点击查看.
点击链接加入群聊【unity unity 3D c# lua 交流】
乞丐并不会妒忌百万富翁,但是他肯定会妒忌收入更高的乞丐。——罗素