Inconsistent Android build (apk) size (sometimes almost double) after Unity update to 2021.3

Hello,

We are having an issue where after we updated our Unity version from 2021.1.28f1 to 2021.3.20f1,
there are inconsistencies when building for the Android platform.

Sometimes the built apk’s size is ~940MB, sometimes it is 1.5GB. This happens without changing any of the settings in Unity. I think Unity/PC restart is a factor here but I cannot be sure. I cannot find a pattern for when it produces the smaller or the bigger size.
We’ve tried to use both scripting backends: mono, il2cpp. For mono we’ve used 32 bit architecture, for il2cpp 64 bit.

We are trying to make a build for the Meta platform (more specifically for the Meta Quest devices).
When we analyze the apk with the Android studio we can see that the total raw file size is ~940MB but the APK size is 1,5 GB.
8874831--1211946--upload_2023-3-14_10-50-10.png
We have only the OpenGLES3 graphics API chosen. And in XR Plug-in Management only the Oculus plug-in.
With this update we set the Minimum API Level to 29 from 23.
Googling hints that this might be the issue (android - Why does minSdkVersion 27 -> 28 double APK size? - Stack Overflow).
Editor logs show that Total User Assets is 1.9gb and complete build size is 3.5gb.

Here is an image of a mono build where I managed to get apk size to 949MB. As you can see, the total Raw File Size hasn’t really changed much. It’s the apk size that has changed.
But what is interesting is that if I look at the editor logs for this build then the Total User Assets is still 1.9gb but complete build size is only 1.9gb, instead of 3.5gb.
8874831--1211970--upload_2023-3-14_11-12-16.png

What’s annoying about this is that it is inconsistent. It more often generates bigger builds than small ones. And it more often happens with il2cpp.

What could be the issue here and how can I solve it?

Best

1 Like

In 2021.3 Android build pipeline switched to incremental build pipeline, thus sequential builds are faster at the cost of reusability, meaning Unity will only rebuild what it considers “requires to be rebuilt”. Previously Unity was always producing builds from zero, it would delete everything and rebuild.

It’s possible there’s a bug with caching, thus you might have extra in your final folder. you can pass https://docs.unity3d.com/ScriptReference/BuildOptions.CleanBuildCache.html to BuildPipeline.BuildPlayer, if you’re building via API. Or alternatively there’s a dropdown button “Clean” next to Build button.

Even if this worked it means I would need to rebuild the library every time I make a build. This is obviously not acceptable as building the library takes around 2-3 hours for us.

I’ve also had this randomly on an old project (but in unity 2020.3), so it’s definitely a rare, but existing bug.
Best bet is probably to submit a bug report, but if it’s not reproducable by QA they can’t do much sadly :confused:

I’m really not sure what’s causing this so it’s even difficult to write a bug report for this. I cannot submit my own project. And I’d like to think this is not an issue in a new project (I haven’t tested though).

I’d be happy to try out different things to get it to work. Just that I’ve tried everything that seems sensible.
For example, I just deleted the Library/Bee/ folder. Opened Unity, made an IL2CPP build and the resulting size is correct. I guess something’s up with caching like Tomas suggested. If I have to delete that folder every time then technically I can live with that but it is extra work and the build takes a few minutes longer.

I feel ya, I had the same.
No new projects I’ve worked with had this issue, so I also can’t make a bug report :confused:

1 Like

I can confirm increased and inconsistent build sizes after upgrading from 2020Lts to 2021Lts and will investigate possible solutions

1 Like

Let us know if you find anything useful!

As I wrote before, the only consistency right now to get the smaller build size is to: close unity, delete Library/Bee/ folder, open Unity and make the build. This hasn’t yet failed a single time. But you can only make one build! Then you need to perform the steps again.

Same here updated from 2020.3.37f1 to 2021.3.22f1 for an Android app. Build size increased from 55 MB to 360 MB.

Using the “Clean Build” option in the dropdown menu of the Build button solved the problem. Probably something in the build cache carried over during the update and screwed things up.

Hi we found another cause for the increased build sizes,
see: Unity 2021.3 not crunching textures

Generally “automatic” crunch compression has stopped working on Unity 2021 LTS - i.e. even when you set the “Use Crunch Compression” flag it falls back to an uncompressed format (ETC2 4Bit) on Android

1 Like

Same issue, building for Android for VR. Using 2022.2.9f1.

Clean build works it but the incremental builds are almost twice the size (380MB → 725MB).

Anyone sent a bug report yet?

If you can reproduce it, definitely file one!

Any update on this bug?

Don’t think it has been reproduced by qa yet

Same issue for me in Unity 2022.3.9f1

First build is 1.8GB, subsequent builds are 3.2GB.

If I use “Clean Build” option it takes about 10 minutes longer but puts out the original 1.8GB size.

First build is 140MB (Small) and later ones is 210MB (Big).

I use 7zip to ckeck apk contents. Opening Small is instant. Opening Big takes around a minute.
Extracting both produce near the same size of 218MB.
Information window for both shows near the same compressed (140MB) and uncompressed (218MB) sizes.

Big have warrnings:

  • Headers Error Unconfirmed start of archive
  • There are some data after the end of the payload data

Big seems corrupted. But somehow it installs and working fine.
Antivirus software does not like Big apk sometimes.

2 Likes

I had a similar problem and I still haven’t solved it, have you found a solution?

Yes, after we updated to 2021.3.32f1 we haven’t experienced this issue.

1 Like

I’m using the 2021.32.f1 too, but experienced the same issue once.
however the increase in size wasn’t too much as compared to previous version. It was only once.
Not facing any issues lately.

Hello. The same problem on Unity 2021.3.37f1 and 2021.3.38f1.
How to reproduce: first clean build - 88.2 mb, second build - 105.2 mb. Next builds can be larger and larger each time. Also it takes a lot of time to build.
Everything is good on 2021.3.36f1 and earlier versions. Every build is 87.8 mb.
Please, fix.

1 Like