Unity使用Strip Engine Code

Code Strip就是代码裁剪。开启代码裁剪,能够在build时将项目中没有用到的代码裁减掉,以减少build出的代码量。

如果使用了il2cpp,由于build过程中先生成CIL然后再生成cpp代码。所以开启Managed code stripping之后,能减少CIL的生成,从而加快cpp生成的过程。

强制保留的方法:

  1. 使用[Preserve]标签,可以对Assembly、Type、Field、Properties、Method使用。
  2. 使用Link.xml文件,在文件中写明需要保留的代码,使用范围同上,还可以标记保留整个Namespace。

https://docs.unity3d.com/Manual/ClassIDReference.html

link.xml放在Assets下

格式如下:

<linker>
       <assembly fullname="mscorlib">
               	<type fullname="System.Reflection" preserve="all"/>
               	<type fullname="System.Security.Cryptography" preserve="all"/>
               	<type fullname="System.Runtime.CompilerServices" preserve="all"/>
               	<type fullname="System.Runtime.InteropServices" preserve="all"/>
               	<type fullname="System.Diagnostics" preserve="all"/>
               	<type fullname="System.Security" preserve="all"/>
               	<type fullname="System.Security.Permissions" preserve="all"/>
       </assembly>
</linker>

猜你喜欢

转载自blog.csdn.net/LM514104/article/details/116210517
今日推荐