Reducing Unity Android build size - android

I'm trying to get the Unity mobile Android APK build size to below 150mb, but it's currently at 170mb. I'm reading through many online docs, but can't find anything that so far reduced my build size. (For reference, I'm creating a "Virtual OS" where many virtual apps are bundled into one, and can be experienced in many different environments, so that increases size.)
My main question is, how can I find the biggest file size "offenders" in my project? Unity's doc tells me to look into the Editor Log's Build Report list, but the files mentioned in the top there (as "uncompressed", e.g. my 20k something PNG becomes a 1+mb file in that list), mainly textures, do not actually help when I next time remove them in another test build. Neither does it relevantly help when I change the Android texture setting to something more highly compressed (e.g. 1024 max Mitchell, which I had for most of my files anyway).
I've tried both APK building, as well as ABB, but both results are quite big. (Switching the API Compatibility Level from .NET 4x to 2 doesn't help either.) I'm compiling to 64bit architecture.
Edit: A first big improvement became removing an (unneeded for Android) Oculus directory (and accompanying Package Manager packages). But this wasn't shown in any charts.
Thanks for any pointers!

Related

How do i find what is increasing the size of my andorid so file

Hey i'm using a native library for my android application and it compiles to an so file of size 2.5 mb. i tried different ways to reduce the size but did not get a solution. i was wondering if i could find out what exactly is causing the size issue by going through the so file is this possible.
When you are using AndroidStudio you can just open the apk in it. It will you the content of it and what size the diffrent components have.
You can analyze APK with APK Analyzer by drag APK file into Android Studio. It will show detail of classes and resources size.
https://developer.android.com/studio/build/apk-analyzer
https://github.com/google/bloaty can show you a breakdown of where the space is being spent. It can also diff two binaries to show you the changes, which is really helpful when trying to figure out what effect any flags you tweak might be having.

Android Studio Duplicate Files

I am getting duplicate files in my source code:
This happens quite often with Android Studio and it happens will all types of files, not just gradle files. It typically happens when I checkout a new branch or swith branches.
What is causing this and how can I prevent it?
As a note, this question was originally posted with image files, thus the image answers. However, this is not limited to image files and I understand why there are multiple image files for different screen densities. I have updated to reflect that there are other files being duplicated.
Do you have a Mac, and is your project stored in your "Documents" directory?
Filenames that include " 2" are generated by iCloud when it can't reconcile two versions of a file. E.g. if you have two computers, and both of them share their "Documents" directories via iCloud, and a file were to be changed simultaneously on both computers, iCloud would wind up creating e.g. a build 2.gradle file.
I found this was happening to me, even though I'm only using one computer to do my work. I suspect that Android Studio may be interacting with iCloud directly, not realizing that it's working on files that are already backed up on iCloud. (See Android Studio generating hundreds of duplicate " 2" files).
I seem to have fixed it by moving my project directory out of Documents. At any rate, I haven't had a problem since I did that.
(Credit to Mike M. for noticing the similarity between our problems.)
Since different devices support different screen densities, all non-vector image drawables should have an image asset for each type of density. So, from a development standpoint, you're using the same Drawable but the app will use the correct image size based on the screen density of the device the app is installed in. I suggest you take a look at this article for more information.
It's ok. Follow the every folder. Folder name is different according to possible phone size Different phone size is different, that’s why they support different size images.

How to load an online android module at run-time?

Is it possible to split my Android apk of 512MB into different parts or modules.
Compile small part of it into a release Apk (small Apk size) for Play Store.
Then fetch the remaining parts or modules from online or your own server during first time install on a device.
Thats:
Small Apk to Google Play Store
Fetch remaining big files after first install.
I am using Android Studio.
Of course you can, that can be easily achieved if you got to split heavy resources(like images, videos, databases). Here you must write some logic which will download that resources and will work with them after a successful download.
I cant imagine a situation when you must to split a code in a separate module, compiled code is light and dont increase apk size so much as another resources. Code can become heavy when there is a lot of code from libraries, in that case I suggest you to learn about Proguard Shrink.
Also you can learn why in android is not possible to load java modules in runtime. On of the reasons is performance given by JIT
Here a is workaround with ndk How do I import shared object libraries at runtime in Android?

The size of freshly new Android project

I created a new project in Android Studio and nothing more (by that I mean having a main activity which does nothing). But when I checked the size of a project folder on my disc I saw it tooks over 40MB! I looked into the project file's content and I saw there folders for which I have questions about:
1) What is the purpose of folder (and it's content) MyProgram/build/generated? Is there a possibility to not create it? (I would save 30MB on my disc by deleting it.)
2) I presume that I shouldn't delete MyProgram/app/build/intermediates so I'm wondering if it'll grow with development of MyProgram? And if the answer is "yes" then how much the size will change? (It tooks almost 10MB now and I'm afraid what will happen when I do something more in my code.)
What is the purpose of folder (and it's content) MyProgram/build/generated?
For a module (e.g., app/) build/generated/ contains Java source code and other files that are generated as part of the build process.
If you are referring to the build/generated/ that appears off of the project root directory, that contains... a JAR. This is an odd place for the build tools to put this particular type of file.
Is there a possibility to not create it?
I don't think so. However, its contents will not go into your APK file. If your development machine is so short on disk space that a 30MB file makes a difference, you will have a very difficult time doing Android development.
I'm wondering if it'll grow with development of MyProgram?
Most likely.
how much the size will change?
That will vary by the size of your app (your code, third-party libraries that you add, etc.) and changes to the build tools over time. It is impossible to tell you exactly how large it will get.
The size from the basic "Hello world" is the minium, doesnt matter if the size is 30 mb or more, is just about the development code, when you generate de APK to share and install your app the basic "Hello world" the size is 2.5 - 3.5 mb. depends from the version of android studio are you using actually, the last version form android studio add somethings.
How i say the real size from you apk is the important, for example if you create the drawables resources for the diferents densities when you install the app just keep 1 density resources, an application size average 7 - 10 mb. A simple app is weird is the size exceeds this numbers.
1) build/ directory and build/intermediates/ is output of the build process,contains Java source code, do not delete.
2) repeat the 1) answer, do not delete.

apk file size increased from 175k to 1711k with minor change -- what's with that?

With the fantastic help of Tim on this thread Controlling Android app with bluetooth mouse/ presenter I added bluetooth remote control of my application. After finishing this, I noticed my apk file went from 175k all the way to 1711k - 10 times larger! I have implemented the bluetooth changes on a test application without seeing any change in file size so I am not sure what caused this. I did have some kind of Eclipse problem in the middle of this and had to do a rebuild to get the source to run again so maybe that had something to do with it.
Searching for file size change here and on Google gives me questions of people who want to make larger files to hold more stuff, not my question. I can't seem to find relevant answers.
The application has no graphics, pdf's, or other files of any size at all. It just reads some GPS stuff, does some math, and displays the results as text.
Is there some way to get the file size back down? Is there an Eclipse option? This is my first real (non test) application and it is finished and working but I am concerned with the file size increase.
You can check the contents of apk file easily. An apk file is simply a zip file with different extension. Just replace .apk with .zip and unzip it. Then diff the contents with your previous .apk file and find out what file makes the difference.
I encountered a similar problem with the APK size. One way to check out which resources are the culprits is to 'Open Editor Log' in Console.
Some helpful explanations can be found here:
Unity build project game 2d to apk with huge size because textures
https://docs.unity3d.com/432/Documentation/Manual/ReducingFilesize.html

Categories

Resources