Search Unity

Tips for making my apk smaller?

Discussion in 'Android' started by Epictickle, Oct 23, 2013.

  1. Epictickle

    Epictickle

    Joined:
    Aug 12, 2012
    Posts:
    431
    Hello!

    I have been making a small running game for andoid for the past month or so, and when I build the apk it is almost 21mb!

    I have been using 3d models off of Turbosquid, and getting free textures wherever I can because I am not a modeler or a texture artist.

    Before we had 3d assets we were using just basic Unity gameobjects like cubes, and the size of the apk was only about 5mb.

    I would like to learn how to optimize the size of the apk while not having to get rid of my assets or create any from scratch, as I am not an artist. If I must create them myself, I will learn how, but I would much rather not have to.

    What are some tips/tricks you used to make your apk smaller?
     
  2. Freezy

    Freezy

    Joined:
    Jul 15, 2012
    Posts:
    234
    Check the editor log it will show you what elements are taking up the most space.
    Unity Console, click on the top right corner (three small lines), Open Editor Log.
    Clear it, save it, build the apk and reload it, there should be a whole section about the resource sizes with KB and % of total.
    Then you will have to do something to those resources.

    Unity can easily reduce the size of textures by tweaking the import settings.
    Models could be stripped of animations if you do not use them.

    Import textures at lower resolutions, then see if they look good enough.
    - You could try all the advanced import settings, try lower resolution with truecolor to retain quality. The texture preview window shows the size of the imported asset, the building apk stage adds compression (which does little to imrpove the size of compressed images)
    - Look at textures that could be generated at runtime (like a red square or gradient) and remove them in favor of code.

    Models hardly take up any space (when compared to a huge texture), but if one of your models does end up being huge, some tweaking might be neccesary to reach your goals. Simplifying a model could be easy if it does not need to be perfect. Even a small gain would be a gain, so experiment away.

    Replacing the assets with assets designed for your current application is still the best bet.
     
  3. Epictickle

    Epictickle

    Joined:
    Aug 12, 2012
    Posts:
    431
    I agree with you 100% Freezy. I am in the process of learning how to model right now, actually.

    I am going to do everything you said, though, and see how much I can reduce the file size. Thank you VERY much Freezy.
     
  4. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    I don't know what is going on with this.

    I cut 10mb off my Total build size by graphics settings changes (as shown by Build Report Tool) yet the .apk has only dropped by ~500k leaving me still above the 50mb limit for google play by ~250k.

    Original Build 37.1mb .apk size 51,148MB
    Optimised Build 24.6mb .apk size 50.245mb

    Over 12mb size reduction but only <1mb reflected in actual .apk

    ???

    Can anyone explain what is going on here?
    What's the point of trying to optimise it if the .apk size is not reflecting the changes?

    ty!
     
    Last edited: Oct 25, 2013
  5. Freezy

    Freezy

    Joined:
    Jul 15, 2012
    Posts:
    234
    Are you using streaming assets or does the project contain a StreamingAssets folder?
    Those would get included in the build regardless of if they are used or not.

    Uncompressed images get good final compression, an image of 5 MB could be cut down to 500kb.
    Check the editor log to see if the build tool might have missed something.
     
  6. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    No, no streaming assets.
     
  7. stylophone

    stylophone

    Joined:
    Aug 16, 2012
    Posts:
    37
    Size of an empty Unity project with stripping level set to micro mscorlib is 7.2mb as apk. 13.8mb for the rest seems ok to me...
     
  8. Epictickle

    Epictickle

    Joined:
    Aug 12, 2012
    Posts:
    431
    Sonic, make sure you have Automatic Compression turned on in the preferences.

    Here is a link to reducing file sizes:
    http://docs.unity3d.com/Documentation/Manual/ReducingFilesize.html



     
    Last edited: Oct 25, 2013
  9. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    Do you mean General Preferences/Compress on import? yes.
    Other textures are also compressed.

    Unless the build report tool is wrong in what it is reporting. It still doesn't answer my original question.
    How can a ~13mb reduction in reported build size (by changing texture settings mainly - which also screwed my NGUI UI, but that's another story) only result in 1mb real reduction in apk?

    ty!
     
  10. Freezy

    Freezy

    Joined:
    Jul 15, 2012
    Posts:
    234
    Explained in my previous post, three options:
    1. Build report is missing assets being included (a folder called StreamingAssets could cause this maybe)
    2. The images are uncompressed and get compressed within the APK, thus they take up much less space then the build report shows
    3. There is a bug and Unity is including more then required.

    NGUI uses texture atlasses right? Perhaps they need to be regenerated as they might be the images that are so large?
    Just guess work as I don't use it.

    As a last resort you could try a workaround to see if you can isolate the issue and find the cause.
    Rebuild the project from the assets you have, it's easier then it sounds.
    Create export packages of each of your scene, filter out as much unreferenced items as you can, then import them into a new project.
    The include dependency's seems a little overzealous in including all kinds of files not used, so some manual checkin/unchecking might be required.
    It doesn't matter if everything works, though it would be ideal if it does (having a proven backup).
    Build and compare the build sizes, see if it made a difference, if there is isolate the causes by comparing the directory's (there are tools for file comparison, just do a internet search).

    Without looking at the project it's hard to support, perhaps you could send it to Unity in a bug report?
    I'm not sure if they support this kind of thing, but it should still be usefull to many people if they at least become aware of the basic need of knowing how large mobile apk's are and what is causing the size to increase.
    If you can't send the project, then the only thing you can do is hacking/slashing through the assets trying to find the one responsible.


     
  11. diegoadrada

    diegoadrada

    Joined:
    Nov 27, 2014
    Posts:
    59
    Hello! Happens to me the same as you you comment. Do you finally could get the answer about what happens?
     
  12. Freezy

    Freezy

    Joined:
    Jul 15, 2012
    Posts:
    234
    Android APK is just a fancy zip file, so uncompressed textures are still getting some compression.
    Compressed textures are already compressed, so there is only a little gain when compressing compressed textures.
     
  13. slimsami

    slimsami

    Joined:
    Jul 29, 2014
    Posts:
    3
    Hi, you sait that an empty project il 7mb, you mean that it's impossible to have packages smaller than 7mb?
    i created a project with just a few buttons and it's aleady 8,5 Mb, so it's not a bug and there is no way to have lighter apk?
     
  14. Freezy

    Freezy

    Joined:
    Jul 15, 2012
    Posts:
    234
    Exactly

    All the parts not being used are still in the engine, nothing we can do about it.
    If you really need it smaller (like a 2D simple application) you might be better off making it as a regular application.

    Unity does however prevent unused assets from being included, which is nice.
    But I am fairly sure some of the built-in fonts and textures sneak in there, as well as DLL's for systems you are not using.