- Home /
How can I exclude unnecessary DLLs from my build?
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?
I found references to the dlls in the various .csproj files and their locations in the Library folder and deleted them by hand, but Unity overwrites those files. :/
If you have UnityScript assemblies that means that you have at least one UnityScript (Javascript) file in your project.
Assembly-UnityScript-firstpass.dll contains all UnityScript files inside the Standard Assets / plugins folder.
Assembly-UnityScript.dll contains all UnityScript files which are placed outside of the Standard Assets / plugins folder.
In general all your scripts inside your project are always included in a build. That's because Unity can't deter$$anonymous$$e which classes are actually used since AddComponent also works with a string argument.
So just remove unused scripts from your project. Chances are high that you have imported some standard assets which are written in UnityScript.
I haven't done builds recently but i don't think $$anonymous$$ono.Security
is included by default. You might use some functions from there ($$anonymous$$D5? SHA?). It's also possible that you have a third party library which relies on those.
System.dll
usually shouldn't be included as well. You might use the System.Xml
namespace somewhere. If you need Xml you either have to accept that one or search for a lightweight xml framework. At least in the past the System.dll
was referenced by the "boo runtime" which is used by the UnityScript runtime. So it might vanish as well if you kick out all UnityScript files.
Not sure about UI / Networking / Analytics
There were indeed some .js files left. I should have let windows search the folders to find them all. After removing the Assembly-UnityScript dlls were gone (3$$anonymous$$B improvement)!
System.dll is there, because I use IEnumerable for Coroutines (System.Collections), Lists (System.Collections.Generic), BinaryFormatter (System.Runtime.Serialization.Formatters.Binary) and FileStream (System.IO). Not sure if I really want to get rid of all that.
$$anonymous$$aybe that's where $$anonymous$$ono.Security comes from. We don't use any plugins as far as I'm aware.
@HypnoticOwl: As far as i know all things you've mentioned are actually defined in the mscorlib. Don't get fooled by the namespace names. Not everything in the System or sub namespace belong to the System.dll
.
For example look at the FileStream docs. It's in the System.IO
namespace but declared within the mscorlib.
You might want to open the System.dll
in ILSpy and see what's actually defined in there which you might be using.
Of course if you use third party stuff it's getting complicated. However with ILSpy you can even figure out which of those assemblies reference which other assemblies.
Hmm it looks like the UnityEngine.dll
is by itself referencing System.dll
, $$anonymous$$ono.Security.dll
and System.Core.dll
. Not sure how well byte-code-stripping works on those...
@Bunny83: Huh, that's weird. That must have changed quite recently. The manual is still clai$$anonymous$$g:
By default, Unity includes only the following DLLs in the built player:
mscorlib.dll
Boo.Lang.dll
UnityScript.Lang.dll
UnityEngine.dll
http://docs.unity3d.com/$$anonymous$$anual/ReducingFilesize.html
I have played around with the Stripping Level in the Player Settings, but that doesn't seem to make a difference.
Do you think this was intentional? $$anonymous$$aybe I should report it...
Answer by masterjohn12 · Nov 13, 2017 at 11:49 AM
I asked it in stack overflow: https://stackoverflow.com/a/47254728/7582969
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
dll error when build 4 Answers
Bringing in classes from a DLL 1 Answer
Using 2 DLLs with the same name 2 Answers