Search Unity

Making an APK under Google Play Instant size limit

Discussion in 'Android' started by copripop, Jun 22, 2018.

  1. copripop

    copripop

    Joined:
    Jun 22, 2018
    Posts:
    7
    I'm trying to create a build that will fit under the 10 MB size limit for an Instant App game as imposed by Google. However I have only managed to get the instant version of my game to around 11 MB and I'm running out of things to take out of the game.

    So I decided to do a test and see what an almost empty Unity project (2018.1.2f1) will produce.
    In this new project I have included the following:
    1. TextMeshPro (the one from Package Manager)
    2. DOTween
    3. 1 Scene containing an animator with an empty animation clip, a particle system (to cause the build to not strip the particle system libraries) and a Canvas
    The items above are the very basics that I require in the game and I think many games have similar basic requirements as well.

    I have also used the Google Play Instant Unity plugin (https://github.com/google/play-instant-unity-plugin) to optimize the project for Play Instant.

    There are no other assets in the included scene and Unity Analytics and Ads and other packages have been removed from the Package Manager for this project.

    The resulting APK for this project is 10806358 bytes, just over the 10 MB size limit making it unacceptable to the Instant App system.

    I would like to know if there are other ways to get the size down without having to remove TextMeshPro or DOTween as that would mean rewriting a lot of code and reworking countless parts of the game just to get an Instant version out which is kinda crazy o_O.
    (FYI TextMeshPro added around 3 MB to the APK size)

    Thanks
     
  2. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    That's a very good question!

    At Unite Berlin 2018, @jonas-echterhoff has had a great talk on optimizing the output binary size. If you missed Unite, I'd expect the recording to be available within a month. He was also showcasing new tooling available in 18.2 beta which helps you understand "what is taking my binary size", along with module disabling.

    You are very close to the limit, so it should be totally doable.
    - are you using mono or il2cpp?
    - do you have stripping enabled?
    - you can remove some of the always included shaders, and modify shader quality for all tiers to match (graphics settings)
    - you can remove the android tv banner (few kb but still :) )
    - finally, you can make use of asset bundles.
     
  3. copripop

    copripop

    Joined:
    Jun 22, 2018
    Posts:
    7
    Thanks, I hope the talk helps!

    I'm using il2cpp, stripping is enabled.
    Not sure how to go about removing the always included shaders though...

    I was actually in the process of changing the game to load from asset bundles and what I had left was a scene that would load the asset bundles.

    Hopefully the module disabling feature will come in handy
     
  4. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    Project Settings - Graphics
    You can find the list of always included shaders together with shader quality there.

    If you make use of audio, make sure to compress it to the max!

    For textures, you may want to use ETC crunch compression - it greatly reduces size at a cost of tiny quality degradation.
     
    liortal likes this.
  5. copripop

    copripop

    Joined:
    Jun 22, 2018
    Posts:
    7
    I've switched over to 2018.2.0f2 in the hopes that the package disabling feature would help. Surprisingly though the APK became slightly larger than in 2018.1.2f1 even though I disabled quite a few unused packages. This is in the almost empty project that I created for testing as mentioned in my first post and contains no textures or audio.

    Could it be possible that the new features increased the size a little?
    Another possibility is that for some reason System.Xml.dll is included in this build even though I have not created any scripts in the project at all and I don't think DOTween and TextMeshPro are referencing it. I don't remember this happening in 2018.1.2f1 though. I'm wondering if something changed in 2018.2 to cause System.Xml to get included...
     
  6. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    So, are you using Mono or IL2CPP? How do you know it's included?
    Would be great if you can check where does this reference come from.
    There should be build report available with stripping info which sheds more light on the module usage.

    BTW the video is finally online:
     
  7. copripop

    copripop

    Joined:
    Jun 22, 2018
    Posts:
    7
    I'm using il2cpp
    I looked at this part of the editor log and saw that it was included:

    Brand new project in 2018.2.0f2
    upload_2018-7-14_0-42-10.png

    Brand new project in 2018.1.6f1
    upload_2018-7-14_0-33-17.png
    I don't know how to check where it's getting referenced from though, I'll go check it out if you can point me in the right direction.

    Player settings on 2018.2.0f2
    upload_2018-7-14_0-45-41.png
    upload_2018-7-14_0-46-39.png

    Cheers!
     

    Attached Files:

  8. m0guz

    m0guz

    Joined:
    Mar 4, 2015
    Posts:
    32
    I also wanted to test Play Instant but it is almost impossible with the current state of the Unity engine. I guess we should wait Core Runtime for Play Instant or create minimal project and implement only Play Instant part.

    Reducing existing project's APK size to 10mb isn't feasible.
     
  9. copripop

    copripop

    Joined:
    Jun 22, 2018
    Posts:
    7
    Don't despair! I'm very very close to getting it under 10 mb (with a minimal project that loads the rest of the game from assetbundles that is). It should be feasible
     
    Yury-Habets likes this.
  10. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    @copripop nunit framework pulls System.Xml in. Do you by chance have any tests enabled? Stripping should've removed it.
     
  11. copripop

    copripop

    Joined:
    Jun 22, 2018
    Posts:
    7
    Ok I just realized that the inclusion of nunit and System.Xml is my fault as I was trying to manually exclude some dlls from getting included by renaming them in the Unity Editor directory (that did not have a significant impact on build size anyway). I've now reset my Unity Editor's files to their default state and Xml and nunit are no longer included.

    Sadly the build size in 2018.2.0f2 is still 200 KB larger than in 2018.1.6f1 even after disabling many of the default but unneeded packages.

    Having said that, I seem to have found a way to get the build down to a size that is acceptable to Google Play Console in Unity 2018.1.6f1. It involves editing the TextMeshPro source in the packages cache that Unity downloads from the Package Manager to remove references to the 3D physics module and recompiling a version of DOTween that also excludes references to the 3D physics module. It's applicable to people who use TextMeshPro and DOTween since having those lead to the size exceeding the allowed limit due to the references to the 3D physics module. I think a game without both of those and without any references to 3D physics will have a build size comfortably under the limit (6+ MB ish).

    Before I expand on how I did it I just want to check if it is legally ok to edit the source of TextMeshPro found in the AppData\Local\Unity\cache\packages\packages.unity.com folder?
     
  12. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    Legal department said that you can modify the source code of TMP according to https://unity3d.com/legal/licenses/Unity_Companion_License
     
    Aashishsinng likes this.
  13. copripop

    copripop

    Joined:
    Jun 22, 2018
    Posts:
    7
    Thanks for checking and providing help on this matter!

    I've written up the things I did to bring the APK size down here

    I hope it'll help whoever encounters the same problems I had :)
     
    lsierra12 and Yury-Habets like this.
  14. ViFilimonov

    ViFilimonov

    Joined:
    Oct 28, 2013
    Posts:
    1
    Hi,
    Try beta version 2018.3 on .net 3.5, the engine is stripp better, which gives an additional 0.7 MB. Build an empty scene takes 5.9 MB.
    You can release an additional 200 KB by replacing all dlls from /Mono/lib/mono/unity_web to /Mono/lib/mono/unity folder.
     
    BlackBindy likes this.
  15. stanbye

    stanbye

    Joined:
    Sep 14, 2015
    Posts:
    2
    hey, copripop, I also want to build an instant app by unity, its that mean I need to create a new build that its version is lower than the install version in google play and has the same package name? I import the google play instant unity plugin, and if I want to show the install dialog in google play while the user is playing the instant app, should I use the code "InstallLauncher.ShowInstallPrompt()”?but I didn't see it while I use the apk build by the unity plugin, can only see this dialog after upload to google play? I would very appreciate if you reply! Thank you!
     
  16. JediNizar

    JediNizar

    Joined:
    Nov 13, 2016
    Posts:
    111
    Hi, I want to say that I'm still learning unity so sorry if my questions are "newbie questions"

    I'm trying to reduce as well my build-size, which is at the moment something about 800MB. and that's is unacceptable especially since my target device is Android Mobile.

    so I've read in this Artikle: https://medium.com/@eyx042/how-to-g...y-instant-if-you-use-textmeshpro-128596110100
    I need to:
    • Remove any unused scripts in your project.
    • Remove unused shaders, prefabs and other assets.
    • Check for any unused/unnecessary components in your scenes or prefabs.
    • Remove unneeded packages that are in your project in the Package Manager.
    I though that unity recognize which asset etc.. is used in my current project.
    Let we say that I have added many scripts, assets, shaders etc.. and some packages into my project. but I'm not using all of them in all my scenes. And for example I want to build each scene separately or group some together in one build and others in another build.
    What I always thought is unity will recognize what to add at the building process, so if the loaded scenes are not using a certain shader, asset or use any of the loaded package, it will just ignore them and not include them in the build.

    Should I create different projects for each of my scenes if I don't want to include them in the same build? what if I create a script at some point, and decide later that I'll not use it or use it in a later state.

    or all the scripts and prefabs that comes for example with the downloaded assets from the assets store, but are not used

    I find it's hard to check what is really used, and also time consuming to delete everything by hand each time.

    what is the right approach? what do u do?
     
  17. BlackBindy

    BlackBindy

    Joined:
    May 9, 2015
    Posts:
    4
    Thanks a lot. In may case, it saved about 0.4 MB. But it is still a huge advance :p
    Now my APK takes 10.3MB. Almost done... almost...
     
  18. Dani_Dev

    Dani_Dev

    Joined:
    May 25, 2017
    Posts:
    1
    sorry i am a
    Sorry for noob question as i am a beginner .Can you guide me through the steps to make instant app?
     
  19. Sholz

    Sholz

    Joined:
    Dec 12, 2016
    Posts:
    20
  20. Dola108

    Dola108

    Joined:
    Oct 8, 2020
    Posts:
    1
    Hello,
    I have looked up all the techniques that i can apply to my project to reduce the apk size. My final apk build size was 9.6MB. However as soon as I integrated firebase analytics in my project, my build size jumped to 12MB. Why would firebase analytics take so much space? I cannot seem to find any way to reduce this size. :(
     
  21. dungdev99

    dungdev99

    Joined:
    Jun 11, 2019
    Posts:
    1
    you build both
    armv7 and arm64?