Managed byte code stripping is always enabled when the IL2CPP scripting backend is used. In this case, the Stripping Level option is replaced with an Boolean option named Strip Engine Code. If this option is enabled, unused modules and classes in the Unity Engine code will be removed. If it is disabled, all of the modules and classes in the Unity Engine code will be preserved.
The link.xml file (described below) can be used to effectively disable bytecode stripping by preserving both types and full assemblies. For example, to prevent the System assembly from being stripped, the following link.xml file can be used:
<linker>
<assembly fullname="System" preserve="all"/>
</linker>
ストリッピングは静的なコード分析に強く依存していて、特に、リフレクションのように動的な機能が使用される場合、効率的に行えないことがあります。そのような場合、どのクラスを対象外とするかの情報をヒントとして渡す必要があります。Unity ではプロジェクト単位のカスタム化されたストリッピングブラックリストが可能です。ブラックリストの使用はいたって簡単です。link.xml ファイルを作成して Assets フォルダー (または、Assets のサブディレクトリ) に置くだけです。link.xml の記載例は以下のとおりです。リストアップされたクラスはストリップされることはありません。
<linker>
<assembly fullname="System.Web.Services">
<type fullname="System.Web.Services.Protocols.SoapTypeStubInfo" preserve="all"/>
</assembly>
<assembly fullname="System">
<type fullname="System.Net.Configuration.WebRequestModuleHandler" preserve="all"/>
<type fullname="System.Net.HttpRequestCreator" preserve="all"/>
<type fullname="System.Net.FileWebRequestCreator" preserve="all"/>
</assembly>
<assembly fullname="mscorlib">
<type fullname="System.AppDomain" preserve="fields"/>
<type fullname="System.InvalidOperationException" preserve="fields">
<method signature="System.Void .ctor()"/>
</type>
<type fullname="System.Object" preserve="nothing">
<method name="Finalize"/>
</type>
</assembly>
</linker>
プロジェクトは複数の link.xml ファイルを持つことができます。各 link.xml ファイルでは、多数のオプションを指定することができます。 assembly 要素はマネージアセンブリを示し、ネストされたディレクティブを記述します。
type 要素は、特定の型の処理方法を示すのに使用されます。type 要素は assembly の子要素でなければなりません。fullname 属性には、1 つ以上の文字に該当するワイルドカード ‘*’ を使用できます。
preserve 属性は以下の 3 つ値のうち 1 つを取ります。
method 要素は、指定したメソッドを保持するために使用します。method 要素は type 要素の子でなければなりません。method は name (名前) または signature (署名) で指定します。
link.xml ファイルに加え、ソースコード内で C# の [Preserve] 属性を使って、リンカーがそのコードをストリップするのを避けることができます。この属性は link.xml ファイルに対応するエントリーとは少し違う挙動をします。
[Preserve] 属性があるような挙動)。ストリップされたアセンブリは、プロジェクトの Temp ディレクトリ下の任意のディレクトリに出力されます (正確な場所はターゲットプラットフォームによって異なります)。オリジナルのストリップされていないアセンブリは、ストリップされたアセンブリと同じ場所にある not-stripped ディレクトリで利用可能です。ILSpy のようなツールを使って、ストリップされた、または、されなかったアセンブリを検証し、コードのどの部分が削除されたかを判断することができます。
2017–09–01 限られた 編集レビュー で修正されたページ
2017–05–26 - Unity 5.6 で Unity ユーザーマニュアルのドキュメントのみを更新
2017–09–01 - Unity 2017.1 で C# [Preserve] 属性の使用に関するヒントを追加
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.