MRTK and Unity managed code stripping
When using Unity's IL2CPP scripting backend (optional in Unity 2018.4, required in 2019 and newer), managed code stripping occurs. Unity's linker performs this process to reduce binary size as well as to decrease build times.
The Mixed Reality Toolkit uses a file, link.xml
, to influence how Unity's linker processes MRTK assemblies. This file, described in full in Unity's documentation,
provides the linker with instructions on how to preserve code when its usage cannot be inferred (ex: used via reflection).
As a flexible and customizable platform, MRTK creates the link.xml
file in Assets/MixedRealityToolkit.Generated
on import, if it is found to not exist. Pre-existing link.xml files
are not overwritten. It is recommended that link.xml
and link.xml.meta
be added to version control. Developers should feel free to customize Assets/MixedRealityToolkit.Generated/link.xml
to meet the needs of the project.
By default, the link.xml file created by MRTK preserves the entirety of the assemblies shown in the following data.
<linker>
<!--
This link.xml file is provided to prevent MRTK code from being optimized away
during IL2CPP builds.More details on when this is needed and why this is needed
can be found here: https://github.com/microsoft/MixedRealityToolkit-Unity/issues/5273
If your application doesn't use some specific services (for example, if teleportation system is
disabled in the profile), it is possible to remove their corresponding lines down
below(in the previous example, we would remove the TeleportSystem below).
It's recommended to start with this list and narrow down if you want to ensure
specific bits of code get optimized away.
-->
<assembly fullname = "Microsoft.MixedReality.Toolkit" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.SDK" preserve="all"/>
<!-- Core systems -->
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.BoundarySystem" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.CameraSystem" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.DiagnosticsSystem" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.InputSystem" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.SceneSystem" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.SpatialAwarenessSystem" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.TeleportSystem" preserve="all"/>
<!-- Data providers -->
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.LeapMotion" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.OpenVR" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.UnityAR" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.WindowsMixedReality.Shared" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.WindowsMixedReality" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.WindowsVoiceInput" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.XRSDK" preserve="all"/>
<!-- Extension services -->
<assembly fullname = "Microsoft.MixedReality.Toolkit.Extensions.HandPhysics" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Extensions.Tracking" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Extensions.SceneTransitionService" preserve="all"/>
</linker>
For more information on the link.xml file format, please refer to the Unity documentation.