The size of your Android app is an important factor to consider. Users are more likely to download your app if it’s relatively small in size, especially if they’re on a slow 2G or 3G connection. Here are a few things you can do to reduce your Android app size.
Android Studio has a neat little feature called “Analyze APK” that lets you, well, analyze an APK file. It shows you useful information like what the APK’s download size would be after it’s published to the Play Store, which parts of your app are taking up the most space, and so on.
Click on “Build” menu in the menu bar at the top, then select “Analyze APK…”.
In the dialog box that appears, choose the path to your generated APK (preferably the release version, because that’s really what you’re interested in optimizing). You should now see the following window.
Here, you can see which parts of your app are taking up the most space. You can stop reading right here if this is what you were after, but if you’re already done this and are looking for more ways to optimize app size, read on.
Evaluate your dependencies
If you haven’t looked at your app’s Gradle build file in a while, you might want to do just that. It’s all too easy to add dependency upon dependency as you come across new libraries your app needs, and then stop using a library but forget to remove the dependency declaration. Removing unneeded Gradle dependencies can then be a great way to reduce your app size. And even if all your dependencies are useful, it’s worth considering which ones you really need if your APK is still too large.
Are your resource files too large?
Resource files are another great place to look when trying to shrink your APK. Find any large images or other media files that are too large and consider compressing them. There are many free image compression services online you can use if you can’t/don’t want to compress them yourself. For PNGs, you can use tinypng.com. It compresses PNG files losslessly, so the quality of the image is preserved despite the drop in size.
This list isn’t exhaustive. I’m pretty sure there are many, many other ways to reduce app size, but these helped me tremendously – I was able to reduce an app from 6 MB down to around 3 MB – that’s half the original size! Now that was probably because of the existing hot mess of large, unused dependencies, so depending on your situation everything I described here may or may not work for you. But I think it’s a good place to start.
Have your own way to optimize app size? Think I got something wrong? Let me know in the comments below!