What is the syntax of link.xml file?

I’m trying to get code stripping to work for my project by listing preserved types in link.xml as instructed here: docs.unity3d.com/Documentation/Manual/iphone-playerSizeOptimization.html.

What is the syntax of this file?

The example shows how to preserve single types. But apparently you can also preserve whole namespaces at a time with namespace-tag. How about wildcards for preserving a set of namespaces? E.g. specifying “System.Net.*” or something similar.

I’d like to know this, too. It seems very hard to find details on setting up link.xml

We’ve found that stripping causes problems with both the Parse and GameSparks plug-ins - and I’m looking for the best way to fix it (without turning stripping off entirely).

Well, link.xml just gives a list of Classes that you don’t want stripped. As the docs show, it’s a list of assemblies, with the must-keep-at-all-cost Classes each contains.

Obviously, what’s hard to working out what Classes code that you did not write depend on. The docs recommend running your code on the emulator and seeing what causes it to crash. I know that’s messy.

After a bit of trial-and-error/process-of-elimination, I managed to fix our GameSparks plugin problem with this link.xml:

<linker>

    <!-- This fixes GameSparks 'ERROR: The authentication 
           or decryption has failed' errors when stripping is enabled -->

     <assembly fullname="mscorlib">
         <type fullname="System.Security.Cryptography.*" preserve="all"/>
     </assembly>

</linker>

I started by looking inside a stripped and unstripped Android .apk, to see which .dll’s where there and which were significantly stripped - and added them all to the link.xml, basically preventing it stripping everything. Once that worked, I started narrowing it down until I was just left with a single assembly, and looked for anything related to the specific problem (the code was running, but giving an error message)

As for the syntax, something that wasn’t clear was whether wildcards where supported - actually, I’m not sure if the ‘.*’ was needed here, or if just ‘System.Security.Cryptography’ would have been included without - I’d seen it in somebody else’s example/attempt, so put that in.

Also, I’d seen this - Parse Platform - and the assembly name of ‘Parse.Unity’ added to the confusion…

Anyway, it’s working now :slight_smile:

1 Like

Nice one. Thanks for sharing.

Looks like namespaces work too.

E.g.

<linker>
  <assembly fullname="Parse.Unity">
    <namespace fullname="Parse" preserve="all"/>
    <namespace fullname="Parse.Internal" preserve="all"/>
  </assembly>
</linker>
2 Likes

Why is there no documentation for this? We shouldn’t have to be analyzing binaries to figure out how an officially supported feature works.

1 Like

http://docs.unity3d.com/Manual/TroubleShootingIPhone.html

Hi guys! If i have several link.xml files, will all of them work? I mean, does Unity combines them somehow in build process?

Does anyone know how to specify generic type definitions in a link.xml file? When the generic type parameter is a struct type, I need to be sure to compile in definitions for each struct type.

Eg:

List
List

@Graham-Dunnett Is it possible to have multiple link.xml files with different names?

@Graham-Dunnett We see from the logs its trying to find different link.xml files.
Can you please confirm if Unity automatically finds it out or we need to merge them to a single Link.xml file and place it under Assets folder?

Please check the attachment.

We are having this problem too. For List you can just add a dummy function that calls new List(); or whatever.
Unfortunately, I have a missing generic type that is in Newtonsoft Json for Unity which is private :frowning:

Also in this boat. @Graham-Dunnett , is there any way of specifying generic types (either closed-constructed or open-constructed) in the link.xml file? The Documentation page doesn’t show any example of that.

I found a strange work around for this if you have some private types you can’t normally access that you need to provoke AOT code generation: You can hack the compiler to not bother with visibility. It’s kind of dirty, but since the code never runs at compile time I don’t feel quite as bad about it.

I would like to know how to setup my link.xml file so that admob doesn’t crash. I want to preserve everything admob needs in the link.xml file. Anyone know what I should preserve or how to find out?

Yes.

There is a more comprehensive doc here: Unity - Manual: Managed code stripping btw

1 Like