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. ...
随机推荐
- Java多线程编程核心技术---线程间通信(一)
线程是操作系统中独立的个体,但这些个体如果不经过特殊处理就不能成为一个整体.线程间的通信就是成为整体的必用方案之一.线程间通信可以使系统之间的交互性更强大,在大大提高CPU利用率的同时还会使程序员对各 ...
- jquery submit()不执行
好吧我承认我竟然犯低级错误了...我忏悔...为了提醒自己置顶一个礼拜 <form id="form" method="post"> <inp ...
- 在hexo静态博客中利用d3-cloud来展现标签云
效果: http://lucyhao.com/tags/ hexo自带的tag cloud的标签展现不太美观,想能够展现出“云”效果的标签.在网上找到了d3-cloud这个项目,github地址:ht ...
- page文件
题目:主页面引用 page 文件 ./configs/style.conf ./templates/main.html <body> <{config_load file=" ...
- 天翼宽带政企网关B2-1P 如何获得超级管理员账号?
RT 用useradmin没办法做NAT,想进telecomadmin里面看看,,,,,并且已经使用过nE7jA%5m这个密码登录,没有用! 求办法!!! 最佳答案 查找超级管理员密码方法: 1.用光 ...
- 【PHP面向对象(OOP)编程入门教程】4.如何抽象出一个类?
上面已经介绍过了, 面向对象程序的单位就是对象,但对象又是通过类的实例化出来的,所以我们首先要做的就是如何来声明类, 做出来一个类很容易,只要掌握基本的程序语法定义规则就可以做的出来,那么难点在那里呢 ...
- CSS相邻兄弟选择器
相邻兄弟选择器定义:选择紧接在另一个元素后的元素,而且两者有着相同的父元素. 代码一:<body> <h1>This is a heading.</h1> < ...
- PHPCMS系统常量
以下系统常量全局可用 APP_PATH 动态程序路径 WEB_PATH 网站根路径 JS_PATH JS路径 CSS_PATH CSS路径 IMG_PATH 图片路径 CACHE_PATH 缓 ...
- jQuery对话框插件 ThickBox
http://baike.haosou.com/doc/7607201-7881296.html 项目已经停止维护,但该插件还是不错的! ThickBox是一个基于JQuery类库的扩展,它能在浏览器 ...
- iOS开发——UI进阶篇(七)程序启动原理、打电话、发短信
一.Info.plist常见的设置 1.建立一个工程后,会在Supporting files文件夹下看到一个“工程名-Info.plist”的文件,该文件对工程做一些运行期的配置,非常重要,不能删除 ...