Unity-StripCode代码剥离
2022-03-12 14:49
585 查看
作用
1.可以删除未使用代码,减少包体大小;
2.不是所有代码都需要转换c++编译,减少构建时间;
使用
PlayerSettings面板others settings中勾选 Strip Engine Code;
Managed Strpping Level 控制剥离级别;
问题
使用代码剥离有可能不会正确删除代码,有概率删除有用代码导致运行出错;
常见错误提示:Default constructor not found for type +类名
解决办法
1.给被误删除的类所在的命名空间前加属性字段——[assembly: Preserve];
2.Assert目录下,添加link.xml文件,其中添加剥离白名单;
官方linker规则:
<linker> <!-- Preserve types and members in an assembly --> <assembly fullname="Assembly1"> <!--Preserve an entire type--> <type fullname="Assembly1.A" preserve="all"/> <!--No "preserve" attribute and no members specified means preserve all members--> <type fullname="Assembly1.B"/> <!--Preserve all fields on a type--> <type fullname="Assembly1.C" preserve="fields"/> <!--Preserve all fields on a type--> <type fullname="Assembly1.D" preserve="methods"/> <!--Preserve the type only--> <type fullname="Assembly1.E" preserve="nothing"/> <!--Preserving only specific members of a type--> <type fullname="Assembly1.F"> <!-- Fields --> <field signature="System.Int32 field1" /> <!--Preserve a field by name rather than signature--> <field name="field2" /> <!-- Methods --> <method signature="System.Void Method1()" /> <!--Preserve a method with parameters--> <method signature="System.Void Method2(System.Int32,System.String)" /> <!--Preserve a method by name rather than signature--> <method name="Method3" /> <!-- Properties --> <!--Preserve a property, its backing field (if present), getter, and setter methods--> <property signature="System.Int32 Property1" /> <property signature="System.Int32 Property2" accessors="all" /> <!--Preserve a property, its backing field (if present), and getter method--> <property signature="System.Int32 Property3" accessors="get" /> <!--Preserve a property, its backing field (if present), and setter method--> <property signature="System.Int32 Property4" accessors="set" /> <!--Preserve a property by name rather than signature--> <property name="Property5" /> <!-- Events --> <!--Preserve an event, its backing field (if present), add, and remove methods--> <event signature="System.EventHandler Event1" /> <!--Preserve an event by name rather than signature--> <event name="Event2" /> </type> <!--Examples with generics--> <type fullname="Assembly1.G`1"> <!--Preserve a field with generics in the signature--> <field signature="System.Collections.Generic.List`1<System.Int32> field1" /> <field signature="System.Collections.Generic.List`1<T> field2" /> <!--Preserve a method with generics in the signature--> <method signature="System.Void Method1(System.Collections.Generic.List`1<System.Int32>)" /> <!--Preserve an event with generics in the signature--> <event signature="System.EventHandler`1<System.EventArgs> Event1" /> </type> <!--Preserve a nested type--> <type fullname="Assembly1.H/Nested" preserve="all"/> <!--Preserve all fields of a type if the type is used. If the type is not used it will be removed--> <type fullname="Assembly1.I" preserve="fields" required="0"/> <!--Preserve all methods of a type if the type is used. If the type is not used it will be removed--> <type fullname="Assembly1.J" preserve="methods" required="0"/> <!--Preserve all types in a namespace--> <type fullname="Assembly1.SomeNamespace*" /> <!--Preserve all types with a common prefix in their name--> <type fullname="Prefix*" /> </assembly> <!--Preserve an entire assembly--> <assembly fullname="Assembly2" preserve="all"/> <!--No "preserve" attribute and no types specified means preserve all--> <assembly fullname="Assembly3"/> <!--Fully qualified assembly name--> <assembly fullname="Assembly4, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> <type fullname="Assembly4.Foo" preserve="all"/> </assembly> <!--Force an assembly to be processed for roots but don’t explicitly preserve anything in particular. Useful when the assembly is not referenced.--> <assembly fullname="Assembly5" preserve="nothing"/> </linker>
相关文章推荐
- VSCode在unity2018中无法补全代码问题解决
- 在 Mac 下配置 Visual Studio Code 为 Unity 代码编辑器
- Unity strip engine code可能会使程序崩溃
- Unity学习记录:新建工程出错/VS Code没有代码提示
- 整合Unity游戏引擎和 Visual Studio Code 代码编辑器
- visual studio code and unity||mac 下使用visual studio 调试unity代码
- 【Unity】【C#】【Code】List示例代码
- visual studio code and unity||mac 下使用visual studio 调试unity代码
- Vscode for Unity Shader 用户代码片段(持续更新)
- 整合Unity游戏引擎和 Visual Studio Code 代码编辑器 第二弹
- Unity strip engine code 遇到執行不能之問題與解決
- codeTool代码自动生成工具(参数类sql数据增删改查语句,实体类,接口代码)
- Unity常用代码
- 用Xcode源代码管理,提交到CSDN的CODE托管代码
- VSCode的一些小操作(二)——快速生成HTML,CSS代码
- Unity 怪物巡逻并攻击玩家C#代码笔记
- vscode自动格式化代码-学习笔记
- [Unity3D学习]Unity代码热更新 源码下载
- LintCode : 第一个错误的代码版本
- Angular 5代码片段和VS Code提升您的工作流程