Unity-managed code stripping (used by link.xml)

The significance of Unity managed code stripping

Managed code stripping can not only reduce the size of the generated dll, and then reduce the size of the installation package, which is especially important for some small stand-alone games, but also can improve the speed of building code and project development.

Setup for Unity Managed Code

Click Player Settings->Player->Managed Stripping Level to enter the following menu:
Unity2020.3.26

  • Low: Code is stripped according to a conservative principle, so very little code is actually stripped and has little effect on package size. This is the default stripping level for unity's il2cpp.
  • Medium: A balance between Low and High, that is, not as cautious as Low, and not as extreme as High
  • High: Prioritizes package size over availability. For usability, use the auxiliary link.xml to artificially reserve the required namespaces or classes in the library.

link.xml is simple to use

  • Define a link.xml file in the Assets directory or its subdirectories
  • Write link.xml in the following format
<linker>
   <!--整个程序集-->
   <assembly fullname="Unity.Mono" preserve="all"/>
   <assembly fullname="Unity.ThirdParty" preserve="all"/>
   <assembly fullname="UnityEngine" preserve="all"/>
   <!--指定程序集中的指定命名空间-->
   <assembly fullname="JsonDotNet">
       <namespace fullname="Newtonsoft.Json" preserve="all"/>
   </assembly>
   <!--指定程序集某个类-->
   <assembly fullname="mscorlib">
       <type fullname="System.Diagnostics" preserve="all"/>
   </assembly>
</linker>
  • When building, Unity will use a tool specifically for managed code stripping, UnityLinker, to perform stripping processing. By default, all assemblies used in unity are merged into an overall assembly, and then according to certain rules, such as game objects in the scene Inherit the object of Monobehavior, mark the root element, and then have the root element for dependency query, and mark other dependent assemblies or classes or namespaces. Finally, the ones that are not marked will be cropped and stripped. When UnityLinker builds, it checks the link.xml file and marks the ignored assemblies or types set in it directly as root elements. So it is guaranteed not to be stripped.

Supongo que te gusta

Origin blog.csdn.net/zhush_2005/article/details/125229154
Recomendado
Clasificación