Upgrading to Unity 2018 added 15mb and unnecessary files to APK

Hi,

I recently upgraded from Unity v5.6.5f1 to v2018.1.0f2 and noticed when I do an android build the APK goes from 104.7mb to 119.2mb.

Build Settings…
Texture Compression: don’t override
ETC2 fallback: 32-bit
Build system: Gradle
Compression Method: default

Player Settings…
Scripting Runtime Version: .NET 4.x Equivalent
Scripting Backend: Mono
Api Compatibility Level: .NET 4.x
Target Architectures: ARMv7 & x86

I have unzipped the APK and found a few interesting things…

  • The files in lib/ have all increased in size slightly (libunity.so gone from 22.6mb to 24mb), but I’m guessing this is to be expected.

  • The file assets/bin/data/unity default resources has gone from 0.7mb to 3.4mb.

  • The files in assets/bin/data/Managed/ used to contain all my plugin dll and 3 unity dll’s, all of which I use in my game (UnityEngine, UnityEngine.Networking and UnityEngine.UI). But now it contains 57 extra UnityEngine dll’s, all things that I don’t use (UnityEngine.VRModule, UnityEngine.TerrainModule, etc…).

If there is anything there that stands out as to why my build size is increasing I would appreciate suggestions. I have tried changing around the build/player settings, but I have yet to get the size down to an acceptable amount to submit to the google play store (Max 105mb).

Thanks.

1 Like

I’ll be interested to hear anything you find on this. I suspect I’ll be dealing with this soon too.

You could try using IL2CPP as it strips out all unused code.
Also runs faster : D

I tried IL2CPP and now it’s coming out at 125.3mb!

I doubt it strips code from Unity’s pre-built libraries which the OP’s problem.

Unity devs suggesting IL2CPP as a means to reduce build size are out of the loop, it increases build size from mono.

OP try the LZ4HC compression., it may be smaller than default. Also set your stripping level to mscorlib.

1 Like

on unity 2018.1.0f2, when i try to build android il2cpp to deal with this issue, clang never completes. it has been running for over 24 hours. I have tried reimporting everything…

3502935--279314--upload_2018-5-19_14-36-50.png

is there a way to find out what clang is choking on? some sort of output somewhere?

  • i found that il2cpp is also not completing on 2017.4.1f1, so my il2cpp issue is likely unrelated. either way, i would love to cull the cruft.

Any update on this? Just updated to 2018 and my filesize went from 43mb to 62mb!

I was able to finally build with il2cpp on 2018.1.0f2- and my apk is 2.5 mb larger than it was with il2cpp on 2017.4.1f1.

Sorry for the delay in replying, I have been away so haven’t been able to try any suggestions until now.

LZ4HC - didn’t reduce the size at all.

mscorlib - Reduced the size by 1.7mb. Seems to have removed some of the unused dlls from assets/bin/data/Managed/ but not all (e.g VehiclesModule.dll has been stripped but ARModule.dll and some others I don’t use remain).

So even with mscorlib enabled, my apk size is still 12.8mb bigger when built with v2018.1.0f2 compared to v5.6.5f1.

I think at this point I will need to resort to doing another optimisation pass of the project assets to make up the gain in size if I wish to keep using 2018.

I’m also interested in build size issues.
Switching build configuration to IL2CPP increases build size by 10 MBs. And I would like to hear the reason by someone who has experience in this field.

If you’re not using all of the .NET 4.x features, try the API Compatibility Level ‘.NET Standard 2.0’
https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-net-standard-2-0/

Just like .Net 3.x has ‘2.0 Subset’, the ‘Standard 2.0’ is essentially lighter .NET 4.x.
The smaller .NET Standard profile will be default at 2018.3 and is our recommended profile for users to target as it
a) exposes a portable/sane set of .NET APIs
b) results in smaller builds.

Although do test on the build and not in the Editor as Editor code always runs against the full profiles: .NET 2.0 with old mono and .NET 4.x with new mono.

Also, while I am not very familiar with the publishing process, maybe splitting ARMv7 and x86 is possible?

Here are some numbers from an absolutely empty new project
.NET4.x - 25 449KB
.NET4.x Standard 2.0 - 24 683KB
.NET4.x Standard 2.0 mscorlib - 21 544KB (Stripping level - mscorlib, but results are very similar on all levels)
.NET4.x Standard 2.0 ‘Strip Engine Code’* IL2CPP - 14 285KB (ARMv7 and x86)
.NET4.x Standard 2.0 mscorlib ARM - 11 055KB (Only ARMv7 build)

  • selecting IL2CPP ‘Stripping level’ drop-down becomes a ‘Strip Engine Code’ checkbox

Also note that the last few months have seen a good bit of active development from our team on code size issues related to the new scripting runtime and the larger .NET profiles. Our goal is to have no regression in size for projects that switch from the old scripting runtime (using either profile) to the new scripting runtime using the .NET Standard 2.0 profile on the same version of Unity.

For the 2018.2 beta, we’ve tested a number of full projects, and we are about 1-2% larger with the new scripting runtime. We’re expecting to close that gap in 2018.3.

Note that there is still generally some size increase in the Unity engine code from one release to another. This is independent of the scripting runtime code size improvement we are making, but it is something we understand and want to correct (one problem at a time though).

@JoshPeterson - We were at roughly the same size from 2017.4 to 2018.1, but we noticed that we had lost x86 support in the upgrade. Once I turned that on, the build increased from ~85MB to ~115MB, which puts us over the Google 100MB limit for uploads to Google Play without expansion files.

That is not too surprising, as a good chunk of that build size is executable code. So enabling x86 will pretty much double the executable size.

Were there any other changes to the project for 2018.1? Did you switch to the .NET 4.x equivalent scripting runtime, for example?

I have the same issue on 2018.3. My apk file size increased from 96MB to 112MB today and exceeded the 100MB limit of Google Play. I was using 2018.3 to build my game yesterday, it was 96MB. But today after only changing a few lines of my code, when I wanted to build the apk, Unity told me that the android sdk is not installed, in the build setting window, it told me to download the sdk, which was not true, I had installed the sdk properly a long time ago. So I restarted Unity, I opened the build setting window again, everything went to normal, I could build the apk as usual. But after building the apk, the apk file size increased suddenly. I had no clue what happened.

Hmm, I having the same issue. Lots of things in the build log that are not being used. For my case, networking is the issue, as I don’t want my Android app to need any permissions, including networking. I’ve posted about this twice now on here, trying to find out what was the issue. Here’s the thread; Why are there unused packages in my build? Specifically, networking. - Unity Engine - Unity Discussions and the earlier one: Why are there unused packages in my build? Specifically, networking. - Unity Engine - Unity Discussions

And here the short of it;

For me, the few kB’s aren’t really the biggest issue. The networking requirement is. Also, I’ve exported the Gradle project to Android studio to look into it more.

As an added thought, I’ve just looked at the build log. I have one empty scene. As in I opened a new scene, saved it and only added that scene to the build. This came out in the build report;

-------------------------------------------------------------------------------
Build Report
Uncompressed usage by category (Percentages based on user generated assets only):
Textures               0.0 kb    0.0%
Meshes                 0.0 kb    0.0%
Animations             0.0 kb    0.0%
Sounds                 0.0 kb    0.0%
Shaders                0.0 kb    0.0%
Other Assets           0.4 kb    0.0%
Levels                 4.7 kb    0.0%
Scripts                623.5 kb    5.2%
Included DLLs          11.1 mb    94.7%
File headers           8.1 kb    0.1%
Total User Assets      11.8 mb    100.0%
Complete build size    68.2 mb
Used Assets and files from the Resources folder, sorted by uncompressed size:
 4.1 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll
 4.1 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/GUISystem/Standalone/UnityEngine.UI.dll
 1.7 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll
 1.7 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/Networking/Standalone/UnityEngine.Networking.dll
 1.5 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/Timeline/RuntimeEditor/UnityEngine.Timeline.dll
 1.5 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/Timeline/Runtime/UnityEngine.Timeline.dll
 0.8 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/TestRunner/UnityEngine.TestRunner.dll
 0.7 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/UnityHoloLens/RuntimeEditor/UnityEngine.HoloLens.dll
 0.7 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/UnityHoloLens/Runtime/UnityEngine.HoloLens.dll
 0.6 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/UnityGoogleAudioSpatializer/RuntimeEditor/UnityEngine.GoogleAudioSpatializer.dll
 0.6 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/UnityGoogleAudioSpatializer/Runtime/UnityEngine.GoogleAudioSpatializer.dll
 0.4 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/UnitySpatialTracking/RuntimeEditor/UnityEngine.SpatialTracking.dll
 0.4 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/UnitySpatialTracking/Runtime/UnityEngine.SpatialTracking.dll
 0.3 kb    0.0% Resources/unity_builtin_extra
 0.1 kb    0.0% Assets/Scripts/BalloonController.cs
 0.1 kb    0.0% Assets/Scripts/SceneController.cs
-------------------------------------------------------------------------------

I know for a fact those last two scripts are not used. They are not in the scene, they are still in the build log. What determines if an Asset is ‘used’ seems to be the question now.