Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

What is the syntax of link.xml file?

Discussion in 'Editor & General Support' started by Antti, Jan 10, 2014.

  1. Antti

    Antti

    Joined:
    Sep 24, 2012
    Posts:
    8
    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.
     
  2. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    643
    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).
     
  3. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    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.
     
  4. bluescrn

    bluescrn

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

    Code (CSharp):
    1. <linker>
    2.  
    3.     <!-- This fixes GameSparks 'ERROR: The authentication
    4.           or decryption has failed' errors when stripping is enabled -->
    5.  
    6.      <assembly fullname="mscorlib">
    7.          <type fullname="System.Security.Cryptography.*" preserve="all"/>
    8.      </assembly>
    9.  
    10. </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 - https://www.parse.com/questions/unity3d-stripping-broken-for-iosandroid-creates-huge-app-size - and the assembly name of 'Parse.Unity' added to the confusion...

    Anyway, it's working now :)
     
    dzmitry-lahoda likes this.
  5. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Nice one. Thanks for sharing.
     
  6. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Looks like namespaces work too.

    E.g.

    Code (CSharp):
    1. <linker>
    2.   <assembly fullname="Parse.Unity">
    3.     <namespace fullname="Parse" preserve="all"/>
    4.     <namespace fullname="Parse.Internal" preserve="all"/>
    5.   </assembly>
    6. </linker>
     
    dzmitry-lahoda likes this.
  7. rchapman

    rchapman

    Joined:
    Feb 13, 2014
    Posts:
    106
    Why is there no documentation for this? We shouldn't have to be analyzing binaries to figure out how an officially supported feature works.
     
    andymads likes this.
  8. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
  9. Leonid

    Leonid

    Joined:
    Aug 20, 2013
    Posts:
    90
    Hi guys! If i have several link.xml files, will all of them work? I mean, does Unity combines them somehow in build process?
     
  10. benjaminjordan

    benjaminjordan

    Joined:
    Jun 29, 2017
    Posts:
    3
    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<int>
    List<float>
     
  11. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    2,002
    @Graham-Dunnett Is it possible to have multiple link.xml files with different names?
     
  12. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    2,002
  13. DavidSWu

    DavidSWu

    Joined:
    Jun 20, 2016
    Posts:
    183
    We are having this problem too. For List you can just add a dummy function that calls new List<int>(); or whatever.
    Unfortunately, I have a missing generic type that is in Newtonsoft Json for Unity which is private :(
     
  14. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    819
    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.
     
  15. shanecelis

    shanecelis

    Joined:
    Mar 26, 2014
    Posts:
    22
    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.
     
  16. telica77

    telica77

    Joined:
    Aug 27, 2017
    Posts:
    6
    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?
     
  17. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Yes.
     
  18. DoN2kcz

    DoN2kcz

    Joined:
    Apr 3, 2020
    Posts:
    5
    sp-LeventeLajtai likes this.