Unity3D 降低IL2CPP编译可执行文件大小
项目开始使用IL2CPP编译,后果是可执行文件急剧增加。
google后发现国外一大神写的方法,原帖在这http://forum.unity3d.com/threads/suggestion-for-reducing-the-size-of-il2cpp-generated-executable.338986/
懒得愿意看原帖的直接看我的方法吧
1、新建一个Mono工程,命名成UnusedByteCodeStripper2,贴如下面代码,编译出 UnusedByteCodeStripper2.exe
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Mono.Cecil;
using Mono.Collections.Generic; namespace RemoveAttributesTool
{
internal class Program
{
private static readonly string[] RemoveAttributesNames =
{
// Just information
"System.Runtime.CompilerServices.CompilerGeneratedAttribute",
"System.Runtime.CompilerServices.ExtensionAttribute",
"System.ParamArrayAttribute",
"System.Reflection.DefaultMemberAttribute",
"System.Diagnostics.DebuggerStepThroughAttribute",
"System.Diagnostics.DebuggerHiddenAttribute",
"System.Diagnostics.DebuggerDisplayAttribute",
"System.Diagnostics.CodeAnalysis.SuppressMessageAttribute",
"System.ObsoleteAttribute",
"System.AttributeUsageAttribute",
"System.MonoTODOAttribute",
// Not relative
"System.CLSCompliantAttribute",
"System.Runtime.InteropServices.ComVisibleAttribute",
"System.Runtime.ConstrainedExecution.ReliabilityContractAttribute",
// Editor only
"UnityEngine.AddComponentMenu",
"UnityEditor.MenuItem",
"UnityEngine.ContextMenu",
"UnityEngine.ExecuteInEditMode",
"UnityEngine.HideInInspector",
"UnityEngine.TooltipAttribute",
"UnityEngine.DisallowMultipleComponent",
"UnityEngine.Internal.ExcludeFromDocsAttribute",
}; private static readonly string[] AdditionalDllFileNames =
{
"UnityEngine.dll",
"mscorlib.dll",
"System.dll",
"System.Core.dll",
"System.Xml.dll",
"Mono.Security.dll",
}; private static void Main(string[] args)
{
// Process for (var i = 0; i < args.Length; i++)
{
switch (args[i])
{
case "-a":
ProcessDll(args[i + 1]);
break;
}
} foreach (var fileName in AdditionalDllFileNames)
{
if (File.Exists(fileName))
ProcessDll(fileName);
} // Run original executables var monoCfgDir = Environment.GetEnvironmentVariable("MONO_CFG_DIR");
var monoPath = monoCfgDir.Substring(0, monoCfgDir.Length - 3) + "bin/mono"; var currentModulePath = Assembly.GetExecutingAssembly().Location;
var orgModulePath = currentModulePath.Substring(0, currentModulePath.Length - 3) + "org.exe"; var orgArgs = '"' + orgModulePath + '"' + ' ' + string.Join(" ", args.Select(a => '"' + a + '"'));
var handle = Process.Start(monoPath, orgArgs);
handle.WaitForExit();
} private static void ProcessDll(string dllPath)
{
AssemblyDefinition assemblyDef; using (var assemblyStream = new MemoryStream(File.ReadAllBytes(dllPath)))
{
assemblyDef = AssemblyDefinition.ReadAssembly(assemblyStream);
} ProcessAssembly(new[] {assemblyDef}); using (var assemblyStream = File.Create(dllPath))
{
assemblyDef.Write(assemblyStream);
}
} private static void ProcessAssembly(AssemblyDefinition[] assemblyDefs)
{
foreach (var assemblyDef in assemblyDefs)
{
foreach (var moduleDef in assemblyDef.Modules)
{
foreach (var type in moduleDef.Types)
RemoveAttributes(type);
}
}
} private static void RemoveAttributes(TypeDefinition typeDef)
{
RemoveAttributes(typeDef.FullName, typeDef.CustomAttributes); foreach (var field in typeDef.Fields)
RemoveAttributes(field.Name, field.CustomAttributes); foreach (var property in typeDef.Properties)
RemoveAttributes(property.Name, property.CustomAttributes); foreach (var method in typeDef.Methods)
RemoveAttributes(method.Name, method.CustomAttributes); foreach (var type in typeDef.NestedTypes)
RemoveAttributes(type);
} private static void RemoveAttributes(string ownerName, Collection<CustomAttribute> customAttributes)
{
foreach (var attrName in RemoveAttributesNames)
{
var index = -1;
for (var i = 0; i < customAttributes.Count; i++)
{
var attr = customAttributes[i];
if (attr.Constructor != null && attr.Constructor.DeclaringType.FullName == attrName)
{
index = i;
break;
}
} if (index != -1)
customAttributes.RemoveAt(index);
}
}
}
}
2、进入Unity目录
Unity/Contents/Frameworks/Tools/UnusedByteCodeStripper2
3、把原来的UnusedByteCodeStripper2.exe命名成 UnusedByteCodeStripper2.org.exe
4、把刚生成 UnusedByteCodeStripper2.org.exe 贴进入。
5、用Unity生成xcode,测试结果
Unity3D 降低IL2CPP编译可执行文件大小的更多相关文章
- Unity3D之如何将包大小减少到极致
http://www.luzexi.com Unity3D之如何将包大小减少到极致,图片是游戏app里最最占空间的资源,所以请各位还没有理解u3d对图片文件存储方式理解的请看<unity3d-t ...
- Unity3D如何减少安装包大小
译官方文档:http://docs.unity3d.com/Manual/ReducingFilesize.html PDF文档:http://www.rukawa.cn/Uploads/Attach ...
- Unity3d+Jenkins 自动编译iOS、Android版本
1.在Unity3d中, 创建导出 iOS.Android 项目脚本 PerformBuild.cs ,放在Editor目录下(必须),如下: using UnityEditor; using Sys ...
- 【转】NDK编译可执行文件在Android L中运行显示error: only position independent executables (PIE) are supported.失败问题解决办法。
原文网址:http://blog.csdn.net/hxdanya/article/details/39371759 由于使用了NDK编译的可执行文件在应用中调用,在4.4及之前的版本上一直没出问题. ...
- Keil C减小代码编译量大小的方法(gai)
keil-C减小代码编译大小的方法整理 方法一:(通过优化代码减小) 1.1少做乘除运算,使用左/右移位来实现乘除 Eg ,普通:a = 0x80*4: 优化:a = 0x80<<2: 1 ...
- python3.6调用c语言动态编译文件 c语言编译可执行文件和动态编译等
1.c的代码 dfunc.c #include<stdio.h> int dgfunc(int n) { ){ ; }else{ )+dgfunc(n-); } } 2.动态编译 cmd ...
- NDK编译可执行文件在Android 中运行显示error: only position independent executables (PIE) are supported.失败问题解决办法。
由于使用了NDK编译的可执行文件在应用中调用,在Android 7.0上的运行情况发现,当运行该可执行文件时,报如下错误: error: only position independent execu ...
- [Unity3D]降低向Shader中传值的开销
Unity3D中提供了很多API用于向shader传值,这篇文章对比测试了两类不同的使用方法的性能. 正文 Unity3D中,通过C#代码向shader传值有两种方式. 一种是面向具体的materia ...
- 008_STM32之_keil编译内存大小解析
Program Size: Code=28784 RO-data=6480 RW-data=60 ZI-data=3900 的含义 1. Code: 程序所占用的FLASH大小,存储在FLASH. ...
随机推荐
- js中自定义事件,使用了jQuery
$(function(){ $('#btn').bind("myClick", function(){ //自定义myClick事件 $('#test').append(" ...
- gradle init.gradle的文件配置 使用
init.gradle文件在build开始之前执行,所以你可以在这个文件配置一些你想预先加载的操作例如配置build日志输出.配置你的机器信息,比如jdk安装目录,配置在build时必须个人信息,比如 ...
- 详细解读PHP时区修改正确方法
.修改PHP.ini这个文件 找到date.timezone这行,去掉前面的分号,改成: date.timezone = Asia/Shanghai .修改 .htaccess文件 修改.htacce ...
- 2015年11月26日 Java基础系列(四)class的定义,继承和实现interface
序,类的设计是JAVA操作的核心,面对对象思想中一切皆对象. 一.类定义中的变量 静态成员变量,为类所有,称为类变量:只有一份,编译时即分配值,使用关键字static声明. 非静态成员变量,每个实例一 ...
- 【AngularJS】—— 6基于AngularJS的过滤与排序
阅读目录 程序设计分析 代码以及结果 前面了解了AngularJS的使用方法,这里就简单的写个小程序,实现查询过滤以及排序的功能. 本程序中可以了解到: 1 angularjs的过滤器 2 n ...
- POJ 3071 Football
很久以前就见过的...最基本的概率DP...除法配合位运算可以很容易的判断下一场要和谁比. from——Dinic算法 Football Time ...
- 关系型数据库ACID
关系型数据库ACID 一.事务 定义:所谓事务,它是一个操作序列,这些操作要么都执行,要么都不执行,它是一个不可分割的工作单位. 准备工作:为了说明事务的ACID原理,我们使用银行账户及资金管理的案例 ...
- Lua模块测试
Lua模块 ---------------------------------------------------------- ----------------------- 模块测试module_ ...
- 利用LruCache为GridView异步加载大量网络图片完整示例
MainActivity如下: package cc.testlrucache; import android.os.Bundle; import android.widget.GridView; i ...
- iOS开发——UI进阶篇(十六)Quartz2D实战小例子
一.画线 只有在drawRect中才能获取到跟view相关联的上下文 - (void)drawRect:(CGRect)rect {} 一条线 // 1.获取跟当前View相关联的layer上下文(画 ...