Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'Android' started by JonBPS, May 11, 2018.

  1. JonBPS

    JonBPS

    Joined:
    Dec 16, 2013
    Posts:
    10
    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...

    1. 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.
    2. The file assets/bin/data/unity default resources has gone from 0.7mb to 3.4mb.
    3. 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.
     
    Kurt-Dekker likes this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    I'll be interested to hear anything you find on this. I suspect I'll be dealing with this soon too.
     
  3. Evaldas_Unity

    Evaldas_Unity

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    83
    You could try using IL2CPP as it strips out all unused code.
    Also runs faster : D
     
  4. JonBPS

    JonBPS

    Joined:
    Dec 16, 2013
    Posts:
    10
    I tried IL2CPP and now it's coming out at 125.3mb!
     
  5. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    I doubt it strips code from Unity's pre-built libraries which the OP's problem.
     
  6. TheJimz

    TheJimz

    Joined:
    Jun 26, 2015
    Posts:
    50
    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.
     
    herb_nice likes this.
  7. herb_nice

    herb_nice

    Joined:
    May 4, 2017
    Posts:
    170
    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...

    upload_2018-5-19_14-36-50.png
     
    Last edited: May 20, 2018
  8. herb_nice

    herb_nice

    Joined:
    May 4, 2017
    Posts:
    170
    is there a way to find out what clang is choking on? some sort of output somewhere?
     
  9. herb_nice

    herb_nice

    Joined:
    May 4, 2017
    Posts:
    170
    * 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.
     
  10. joelcarlson

    joelcarlson

    Joined:
    Apr 7, 2014
    Posts:
    47
    Any update on this? Just updated to 2018 and my filesize went from 43mb to 62mb!
     
  11. herb_nice

    herb_nice

    Joined:
    May 4, 2017
    Posts:
    170
    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.
     
  12. JonBPS

    JonBPS

    Joined:
    Dec 16, 2013
    Posts:
    10
    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.
     
  13. Deleted User

    Deleted User

    Guest

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

    Evaldas_Unity

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    83
    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
     
    Last edited: Jun 4, 2018
  15. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    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).
     
  16. pfleetwood22

    pfleetwood22

    Joined:
    Jun 6, 2016
    Posts:
    28
    @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.
     
  17. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,921
    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?
     
  18. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    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.
     
  19. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    207
    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; https://forum.unity.com/threads/why...-specifically-networking.600340/#post-4013656 and the earlier one: https://forum.unity.com/threads/why...-specifically-networking.600217/#post-4013437

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

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    207
    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;

    Code (csharp):
    1. -------------------------------------------------------------------------------
    2. Build Report
    3. Uncompressed usage by category (Percentages based on user generated assets only):
    4. Textures               0.0 kb    0.0%
    5. Meshes                 0.0 kb    0.0%
    6. Animations             0.0 kb    0.0%
    7. Sounds                 0.0 kb    0.0%
    8. Shaders                0.0 kb    0.0%
    9. Other Assets           0.4 kb    0.0%
    10. Levels                 4.7 kb    0.0%
    11. Scripts                623.5 kb    5.2%
    12. Included DLLs          11.1 mb    94.7%
    13. File headers           8.1 kb    0.1%
    14. Total User Assets      11.8 mb    100.0%
    15. Complete build size    68.2 mb
    16. Used Assets and files from the Resources folder, sorted by uncompressed size:
    17.  4.1 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll
    18.  4.1 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/GUISystem/Standalone/UnityEngine.UI.dll
    19.  1.7 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll
    20.  1.7 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/Networking/Standalone/UnityEngine.Networking.dll
    21.  1.5 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/Timeline/RuntimeEditor/UnityEngine.Timeline.dll
    22.  1.5 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/Timeline/Runtime/UnityEngine.Timeline.dll
    23.  0.8 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/TestRunner/UnityEngine.TestRunner.dll
    24.  0.7 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/UnityHoloLens/RuntimeEditor/UnityEngine.HoloLens.dll
    25.  0.7 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/UnityHoloLens/Runtime/UnityEngine.HoloLens.dll
    26.  0.6 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/UnityGoogleAudioSpatializer/RuntimeEditor/UnityEngine.GoogleAudioSpatializer.dll
    27.  0.6 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/UnityGoogleAudioSpatializer/Runtime/UnityEngine.GoogleAudioSpatializer.dll
    28.  0.4 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/UnitySpatialTracking/RuntimeEditor/UnityEngine.SpatialTracking.dll
    29.  0.4 kb    0.0% C:/Program Files/Unity/Hub/Editor/2018.2.17f1/Editor/Data/UnityExtensions/Unity/UnitySpatialTracking/Runtime/UnityEngine.SpatialTracking.dll
    30.  0.3 kb    0.0% Resources/unity_builtin_extra
    31.  0.1 kb    0.0% Assets/Scripts/BalloonController.cs
    32.  0.1 kb    0.0% Assets/Scripts/SceneController.cs
    33. -------------------------------------------------------------------------------
    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.
     
  21. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Generally all scripts are compiled into a single DLL (techically a few different DLLs, see the contents of Library/ScriptAssemblies), whether they are used or not.

    Then at final build time, they go into the target binary, and there MAY be stripping that happens.

    If you are building IL2CPP, the stripping works quite differently, and again unused code MAY be removed.

    Details are unclear and subject to change with every version of the toolchains. Google for yourself.

    Either way, 0.1k times 2 is unlikely to sink your battleship.
     
  22. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    Today when I was building iOS, I encountered the same problem. Unity told me that I didn't install the iOS support, but this is not true. So I switched the target platform to standalone, and opened the build setting window, it said that I needed to download iOS support, however, I actually had already installed it. So I just restarted Unity, I open the build setting window again, everything went back to normal, I could build iOS as usual. But this time, the final build size didn't get increased compare to the last one. So I can safely say that the suddenly increase of the Android build size is not relevant to the issue I described here.
    I tried the build size reducing techniques that Unity staffs mention here, I tweaked some of the settings in Player Setting, I managed to reduce my apk file size to 99MB. However, it didn't explain why build size suddenly increased by 16MB, my build size was 96MB and it didn't require any tweaking.
     
    Last edited: Dec 20, 2018
  23. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    207
    Well that makes sense. Thanks. What doesn't make sense is that I haven't found a way yet to create an SDK that didn't require network permissions. ( https://forum.unity.com/threads/why...-specifically-networking.600340/#post-4016251 )

    Starting to doubt if that is even possible at all.
     
  24. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    I am using Unity 2018.3.02f, I found that if we don't uninstall the unnecessary packages in the Package Manager, Unity will include useless dll files in the build because these unnecessary packages are using these dll files. I successfully removed these useless dll files by uninstalling the unnecessary packages in the Package Manager without modifying the AndroidManifest.xml. However, even if we get rid of the useless dll files, it's only a few KB of difference, the problem here is that our build size suddenly increases by 16MB for unknown reason, so the useless dll files are definitely not the source of the problem here.
     
  25. LoekvanKooten

    LoekvanKooten

    Joined:
    Apr 3, 2017
    Posts:
    120
    I went from 2 GB to more than 6 GB spread over three asset files. This is absolutely ridiculous: it is exactly the same game, and now none of my textures render because of an issue that has been persisting since september last year: Unity claiming to be 64 bit while it isn't and can't handle asset files larger than 4 GB.
     
  26. FernandoMK

    FernandoMK

    Joined:
    Feb 21, 2017
    Posts:
    178
    I walk with similar issues, my APKs still empty, comes with a 25MB and 30MB. I hope Unit 2019 can address these unused native size issues and native references.

    sorry about my English :p