3

What should you do when the IL2CPP compiler starts striping your code from your external assemblies (dll) in you iOS builds. Causing your JSON De/serialization code to break.

UberGeoff
  • 192
  • 6

1 Answers1

3

1) Make sure you are using the Unity3d "tuned" version of JSON.Net. You can find the latest version here: Json.Net.Unity3D. This version does not make use of dynamic code - thus is "safe" for Ahead-of-time compilers.

2) Make sure you add the correct preservation lines into your Unity3D "link.xml" file:

<linker>
  <assembly fullname="AssemblyName.Common">
     <type fullname="AssemblyName.Common.*" preserve="all" />
   </assembly>
</linker>

The * will ensure that all namespaces as well as all classes are preserved - and will not be stripped.

That should do it.

Kay
  • 12,918
  • 4
  • 55
  • 77
UberGeoff
  • 192
  • 6
  • Unless you are doing something really complicated you should be using Unity's built `JsonUtility`. Although it's good to know what's in this answer. – Programmer Jul 07 '17 at 07:27
  • JsonUtility is very basic, i would recommend the exact opposite: you should only use it if you're doing something that is super simple. – lysergic-acid Jul 15 '17 at 18:16
  • 1
    lysergic-acid - I think you and Programmer are saying the same thing here. Over and above this - my original post was intended to focus more on the aggressive stripping that can occur using the IL2CPP compiler for AOT targeted builds. More about that here: [link](https://docs.unity3d.com/Manual/ScriptingRestrictions.html) – UberGeoff Jul 17 '17 at 04:57