I took the generated apk file and I put it in the apk analyzer tool that's built into Android Studio. You can find it in "Build/Analyze APK...". The results were quite interesting and led me to some further steps. BTW, if you don't know how to handle Android Studio, you can just change the apk file's extension to zip, unzip the file and analyze its contents manually. It won't be as efficient but it'll do.
What I soon found out was that what took the most space in the apk file were not my graphic assets nor my code but the native libraries in the lib folder. They were split into two subfolders: x86 and armeabi-v7a each of roughly 10MB.
I started thinking if I could get rid of some of them and it turned out that I could. The answer was to build the project for each architecture (arm and x86) separately and then publish them both on Google Play. This way each version would be around 15MB in size and it would be distributed to appropriate, compatible devices automatically. Here's how I did it.
I went to the Build Settings (File/Build Settings...) and I found Other Settings/Configuration/Device Filter. It was set to FAT (ARMv7 + x86). I switched it to ARMv7, built it and then did the same for x86, saving it in a different file and incrementing the version name and version code beforehand (Other Settings/Identification/Version and Other Settings/Identification/BundleVersionCode).
This way, I have two active apk files now, both with a different version name and version code and both targeted at different device architectures. When someone installs my game from Google Play, they get only the version compatible with their device, which is now 10MB lighter. Yes, it costs me a bit more work to create two separate apk files and then publish them on Google Play but I think it's worth the effort. I created a script that builds the two versions from the command line but it's a subject for a different post perhaps.
I hope my investigation will help you make your Unity Android game leaner too. If something is not clear for you, make sure to post your questions in the comments and I'll do my best to answer them.
No comments:
Post a Comment