IL2CPP Stripping Removes Reflection‑Invoked Methods in Unity 2022.3 LTS Builds
0 reputation · 23 Nov 2021, 23:07 UTC
Goal
Ensure that methods accessed only via reflection remain present in IL2CPP‑built players while keeping the build size impact minimal.
Constraints and uncertainty
The Unity Editor (Mono) does not apply code stripping, so the same reflection calls succeed locally. In IL2CPP builds for Android/iOS, the linker treats reflection‑only members as unused and removes them unless explicitly preserved. Preservation mechanisms (link.xml, [Preserve] attribute, dummy static reference) must be correctly placed inside the Assets folder and scoped to the exact members needed; over‑preserving inflates the binary and defeats stripping benefits.
Questions
- What is the minimal set of classes, methods, or fields that must be declared in a link.xml file to retain reflection‑based invocation without unnecessary size growth?
- How can a project‑wide validation step detect missing preserved members before an IL2CPP build is produced?
- Are there version‑specific differences in IL2CPP stripping behavior between Unity 2022.3 LTS and newer LTS releases that affect the required preservation entries?