如何从构建中排除不必要的DLL?

时间:2017-11-12 10:48:04

标签: unity3d optimization dll unity5 game-engine

我试图优化游戏的文件大小,特别是android版本。我已经优化了资产并将构建剥离级别设置为使用micro mscorlib。但是,查看Editor.log会发现DLL仍然占用了50%以上:

 Textures      2.7 mb     35.7% 
 Meshes        80.5 kb     1.0% 
 Animations    0.0 kb     0.0% 
 Sounds        0.8 kb     0.0% 
 Shaders       98.2 kb     1.3% 
 Other Assets  177.9 kb     2.3% 
 Levels        110.0 kb     1.4% 
 Scripts       447.4 kb     5.8% 
 Included DLLs 3.9 mb     52.2% 
 File headers  26.2 kb     0.3% 
 Complete size 7.5 mb     100.0% 

3.9mb似乎有点多,所以我看看实际添加了哪些DLL。我发现了这个:

 Mono dependencies included in the build
 Dependency assembly - Mono.Security.dll
 Dependency assembly - System.Core.dll
 Dependency assembly - System.dll
 Dependency assembly - mscorlib.dll
 Dependency assembly - UnityEngine.UI.dll
 Dependency assembly - UnityEngine.Networking.dll
 Dependency assembly - UnityEngine.Analytics.dll
 Dependency assembly - Assembly-CSharp.dll
 Dependency assembly - Assembly-UnityScript-firstpass.dll
 Dependency assembly - Assembly-UnityScript.dll

这看起来可以改进很多。我没有使用UnitScript,所以Assembly-UnityScript-firstpass.dll和Assembly-UnityScript.dll应该已经过时了。我也不使用网络或分析,因此也可以删除它们。不确定Mono.Security.dll的作用或UnityEngine.UI.dll是否真的有必要。 所以,知道这一点,我怎样才能摆脱这些看似不必要的DLL?

3 个答案:

答案 0 :(得分:3)

似乎没有直接的方法来做到这一点。我刚刚尝试删除测试项目中的一些dll引用,但还不够。 Unity无论如何都在构建中包含了一些已删除的库。

但是,如果我们不可能团结一致来找到那些元素呢?这种方法奏效了。

<小时/> 步骤:

  1. 删除Assembly-CSharp和Assembly-CSharp-firstpass中的引用

    Edit references in project

    References list

  2. 按照路径将已删除的dll重命名为其他内容,例如filename.dd_old

    Follow the path of those dlls

    Rename those dlls

  3. 3.-编译,构建并查看结果:)

    在:

    Mono dependencies included in the build
    Dependency assembly .....
    Dependency assembly - UnityEngine.UI.dll
    Dependency assembly - UnityEngine.Networking.dll
    Dependency assembly - UnityEngine.SpatialTracking.dll
    Dependency assembly .....
    

    后:

    Mono dependencies included in the build
    Dependency assembly .....
    Dependency assembly - UnityEngine.UI.dll
    Dependency assembly - UnityEngine.SpatialTracking.dll
    Dependency assembly .....
    
    1. 测试你的游戏,我真的不知道这种做法有什么不妥,我的意思是,我真的不知道这种做法不会出错:D

    2. _old个文件重命名为下一个项目的原始名称等。

答案 1 :(得分:3)

还有另一种方法:

第1步:右键单击.apk文件并使用WinRAR / ZIP打开

第2步:输入资源文件夹,然后输入bin \ Data \ Managed

第3步:在那里你会找到所有的DLL,只需删除你想要的东西(不是那么多:D) enter image description here

答案 2 :(得分:0)

Unity提供了一项功能,可以为您剥离未使用的代码,从而消除dll。

请遵循以下步骤:

  1. 选择菜单编辑->项目设置
  2. 项目设置对话框中,选择播放器
  3. 播放器中,选择其他设置
  4. 向下滚动直到 Optimization (优化)部分。
  5. 在下拉列表中更改选项 Managed Striping Level

此功能有很多选项,您甚至可以使用 Assets 文件夹中的 link.xml 文件链接特定的程序集。

我强烈建议您阅读Unity官方文档Managed Code Stripping以获得更多信息。

就是这样。希望对您有所帮助。

相关问题