How can I exclude unnecessary DLLs from my build?
Asked Answered
E

3

7

I'm trying to optimize the file size of my game, in particular the android build. I have optimized the assets and set the build stripping level to Use micro mscorlib. However, looking at the Editor.log reveals the DLLs still take up more than 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 seemed a bit much, so I looked at which DLLs are actually added. I found this:

 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

This looks like it can be improved quite a bit. I don't use UnitScript, so Assembly-UnityScript-firstpass.dll and Assembly-UnityScript.dll should be obsolete. Neither do I use Networking or Analytics, so these could be removed as well. Not sure what Mono.Security.dll does or whether UnityEngine.UI.dll is really necessarry. So, knowing this, how can I get rid of these seemingly unnecessary DLLs?

Empurple answered 12/11, 2017 at 10:48 Comment(1)
Wow!! I am getting included.dll 13mb in emtpy-sample scene project.Sussi
H
3

Seems like there is not a direct way to do that. I just tried removing some dlls references on a test project and wasn't enough. Unity was including some of the removed libraries in the build anyway.

But, what if we make impossible to unity to find those elements? That approach worked.


Steps:
  1. Remove references in Assembly-CSharp and Assembly-CSharp-firstpass

    Edit references in project

    References list

  2. Follow the path and rename those removed dlls to something else, like filename.dd_old:

    Follow the path of those dlls

    Rename those dlls

3.- Compile, Build, and see the results :)

Before:

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 .....

After:

Mono dependencies included in the build
Dependency assembly .....
Dependency assembly - UnityEngine.UI.dll
Dependency assembly - UnityEngine.SpatialTracking.dll
Dependency assembly .....
  1. Test your game, I really don't know what can be wrong with this practice, and I mean, I really don't know what cannot go wrong with this practice :D

  2. Rename the _old files to their original names for the next project, etc..

Haunt answered 12/11, 2017 at 22:29 Comment(2)
Great answer. There is another way: If you build an apk, you open it with WinRAR and go to "\assets\bin\Data\Managed". There you will find all DLLS. I just removed them, and as well as you, I really don't know what can be wrong with this practice.Empurple
You should write that answer too! I think that is easier that what I posted!Haunt
E
4

There is another way of doing this:

Step 1: Right-click on the .apk file and Open it with WinRAR/ZIP

Step 2: Enter the assets folder, then enter bin\Data\Managed

Step 3: There you will find all the DLLs, just remove what you want (not that much :D) enter image description here

Empurple answered 13/11, 2017 at 23:39 Comment(0)
H
3

Seems like there is not a direct way to do that. I just tried removing some dlls references on a test project and wasn't enough. Unity was including some of the removed libraries in the build anyway.

But, what if we make impossible to unity to find those elements? That approach worked.


Steps:
  1. Remove references in Assembly-CSharp and Assembly-CSharp-firstpass

    Edit references in project

    References list

  2. Follow the path and rename those removed dlls to something else, like filename.dd_old:

    Follow the path of those dlls

    Rename those dlls

3.- Compile, Build, and see the results :)

Before:

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 .....

After:

Mono dependencies included in the build
Dependency assembly .....
Dependency assembly - UnityEngine.UI.dll
Dependency assembly - UnityEngine.SpatialTracking.dll
Dependency assembly .....
  1. Test your game, I really don't know what can be wrong with this practice, and I mean, I really don't know what cannot go wrong with this practice :D

  2. Rename the _old files to their original names for the next project, etc..

Haunt answered 12/11, 2017 at 22:29 Comment(2)
Great answer. There is another way: If you build an apk, you open it with WinRAR and go to "\assets\bin\Data\Managed". There you will find all DLLS. I just removed them, and as well as you, I really don't know what can be wrong with this practice.Empurple
You should write that answer too! I think that is easier that what I posted!Haunt
C
3

The Unity provides a feature to strip unused code, and therefore the dll, for you.

Follow the steps below:

  1. Select the menu Edit->Project Settings.
  2. In the Project Settings dialog box, select Player.
  3. In the Player select Other Settings.
  4. Scroll down until the Optimization section.
  5. Change the option Managed Striping Level in the dropdown list.

This feature has many options and you can even link the specific assemblies using a link.xml file in the Assets folder.

I strongly suggest to read the Unity official documentation Managed Code Stripping for further information.

That's it. Hope it helps.

Checked answered 11/7, 2019 at 5:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.