If it is one thing that I hate – it is apps that are HUGE downloads for really simplistic functionality.
40MB for an app that just accesses some messages and has hardly any images, what is it doing??
I have recently had quite an obsession trying to reduce my app size and have managed to shave off 6MB with a few optimisations (Yay right?!!!! 😃). I thought I would share some tips on how to reduce your Android APK file size:
- Use ProGuard: this will obfuscate your code and reduce the app size. [1]
- Enable the following with gradle:
- minifyEnabled – this will get rid of unused code.
- shrinkResources – this will get rid of unused resources such as layouts or strings that are not referenced in your app.
buildTypes { release { shrinkResources true minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-project.txt' signingConfig signingConfigs.config } }
- Make use of split APKs. This is especially useful if you are using native libraries. The native libraries can be quite large and making a user download an x86 library when their device is ARMv7 is pointless. Strip that out. [2]
- Check your images. If there are any large bitmaps, chances are you can reduce the size without losing much detail in the image. If possible, use JPEGs instead of PNGs as they are generally smaller.[3]
- Consider using Vector Drawables instead of PNGs for every density bucket. This will reduce the number of files needed and the images won’t degrade in quality.[4]
- Don’t use images if you don’t need to. Gradient backgrounds, shapes or colours can be achieved with XML instead.[5]
- Consider the libraries you use. If a library is massive and you are only using one or two functions you should find an alternative smaller option. Look through your code to see if there are any unused JAR files or unused code and remove that too.
Be careful when doing the things listed above, make sure you test thoroughly after applying these changes as it could break parts of your app. It could get rid of resources or code that might be used.
What do you do to reduce the size of your APKs?
Leave a Reply
You must be logged in to post a comment.