Recently I was working on a project with a large amount of png files. Our designers had created a bunch of custom assets and animations for the project. After resizing the assets for different screen densities the project was left bloated from all the png files. It was compiling (with progaurd enabled) to over 150mb. Even though Google recently raised the apk size limit from 50mb to 100mb, we were still way oversized.
I had read a while back about Google’s webp image format and figured it would be worth a shot to try it out. Boy was I shocked. By converting our images from png format to webp format I was able to reduce our apk size from over 150mb to 34mb.
I was able to reduce our apk size from over 150mb to 34mb.
But what about compatibity?
Webp is natively compatible with Android 4.0 and higher. This makes it the perfect solution for most modern projects.
On Windows you can install this codec to enable you to view the images in any photo viewer. Unfortunately there is no such plugin from Google for Mac. I did find this tool for Mac, but I haven’t tried it.
Let’s do it!
The Google Play store does not allow an apk to use .webp for the app icon. In in the Mac Bash script below I’ve set it to skip mipmap directories because that is where my app icons are. The Windows batch script does not check for this.
Also, these scripts will overwrite your png file. Make sure to back them up!
Here’s a Windows batch script I wrote to easily convert the entire project to webp. Just replace the two comments with your path structure.
If you perfer Mac here’s a bash script.
You can change the quality level by raising or lowering 80. I found no visible loss of image quality at 80. Remember, your users will be on small phone screens and will not be able to analyze every pixel like you can on your desktop.