Preventing Code Stripping for Newtonsoft.Json
March 11, 2026 · View on GitHub
Overview
Some EOS samples and certain custom implementations may rely on Newtonsoft.Json for JSON serialization and deserialization.
When building with IL2CPP and Managed Code Stripping enabled, Unity may remove unused or reflection-referenced members from assemblies.
Because Newtonsoft.Json uses reflection heavily, this can lead to missing types at runtime (especially in Android, iOS, and WebGL builds).
Some parts of the EOS Unity Plugin rely on type converter classes that IL2CPP may incorrectly remove.
This affects several authentication flows, including Exchange Code Auth where the login callback may never complete and remain stuck in a state.
This section describes how to prevent code stripping and ensure consistent runtime behavior.
Important
The link.xml file must be placed inside your project’s Assets/ directory, otherwise it will be ignored.
When This Applies
You should perform this step if any of the following are true:
- Your project uses Newtonsoft.Json directly (e.g.,
JsonConvert.SerializeObject,JsonConvert.DeserializeObject). - You are using EOS sample scenes that depend on Newtonsoft.Json.
- You are building to Android, iOS, WebGL, or any platform using IL2CPP.
Steps to Prevent Stripping
- In your Unity project in Assets folder, create a new file link.xml
- Add the following content:
<linker>
<assembly fullname="Newtonsoft.Json" preserve="all" />
<assembly fullname="com.playeveryware.eos.core">
<type fullname="PlayEveryWare.EpicOnlineServices.ListOfStringsToPlatformFlags" preserve="all"/>
<type fullname="PlayEveryWare.EpicOnlineServices.ListOfStringsToAuthScopeFlags" preserve="all"/>
<type fullname="PlayEveryWare.EpicOnlineServices.ListOfStringsToIntegratedPlatformManagementFlags" preserve="all"/>
<type fullname="PlayEveryWare.EpicOnlineServices.ListOfStringsToInputStateButtonFlags" preserve="all"/>
<type fullname="PlayEveryWare.EpicOnlineServices.StringToTypeConverter`1" preserve="all"/>
</assembly>
</linker>
Note
If your project conditionally includes Newtonsoft.Json, or you want to avoid warnings when the assembly is not present, you may use:
<linker>
<assembly fullname="Newtonsoft.Json" preserve="all" ignoreIfMissing="1" />
</linker>
If size is critical, you may scope preservation to specific types/members instead of preserve="all". See Unity’s Link XML reference.