Collin Dauphinee
Collin Dauphinee

Reputation: 13993

How can I prevent a pre-built assembly in my Unity package from being stripped?

I have a Unity package that contains a pre-built assembly.

This assembly is not aware of Unity and contains some models that are used for deserialization. I've run into a problem where il2cpp is stripping the constructors of these models, because they're only invoked via reflection.

I don't seem to be able to provide a link.xml in my package, and because the assembly isn't aware of Unity, I can't use the [Preserve] attribute.

Is there any way for me to ensure that il2cpp leaves these constructors intact, without requiring manual steps after a user installs my package?

Upvotes: 0

Views: 1196

Answers (2)

Specter
Specter

Reputation: 31

In addition to the buxter-s answer - you can also preserve only the constructors from stripping:

<linker>
    <assembly fullname="AssemblyName">
        <type fullname="*">
            <method name=".ctor"/>
        </type>
    </assembly>
</linker>

See also: https://learn.microsoft.com/en-us/xamarin/cross-platform/deploy-test/linker

Upvotes: 0

buxter
buxter

Reputation: 593

You can specify not to strip the assembly in the link.xml or disable Stripping at all.

The link.xml would look like this:

 <linker>
     <assembly fullname="Assembly1">
     <type fullname="Assembly1.A" preserve="all"/>
 </linker>

Or Player Settings -> Optimization -> Managed Stripping Level set to 'Disabled' will turn off code stripping

Upvotes: 0

Related Questions