views:

100

answers:

2

I've been curious as to all the optimizations that go into the building of an .apk. I'm curious because of two things I've tried in the past to bring down the size of my .apk:

  1. I have had a few large json assets in projects before, as well as a static sqlite database. I tried bringing down the size of the apk by gzipping them before the build process, but the resulting size is exactly the same.

  2. I just today tried pngcrush on my /drawable/ folders. The resulting build was exactly the same size as before.

I would think that perhaps #1 could be explained by the zip process, but simply zipping the /drawable/ folders in #2 result in different-sized files. Perhaps the build process runs something akin to pngcrush?

Regardless, I was wondering if anyone knew where to find a detailed description of all the optimizations in the Android build process. I don't want to waste my time trying to optimize what is already automated, and also I think it'd help my understanding of the resulting apk. Does anyone know if this is documented anywhere?

A: 

One thing that will help when you use PNG images is to use indexed PNG (gimp can convert it easily). Indexed PNG files are about one third the size of the "normal" PNGs. If you have lots of images then it really helps reduce the package size.

omermuhammed
The thing is, pngcrush reduced the size of my files dramatically (~70% reduction) but the resulting APK was the same size.
Daniel Lew
aapt already performs png optimizations. We tried to add pngcrush to the process but it was not reliable enough and was breaking some of our assets.
Romain Guy
A: 

these two are lightly 'documented' optimizations.

http://developer.android.com/guide/developing/tools/aapt.html "... Zip-compatible archives (... apk) ... " although I'm not sure that it uses 'maxmimum' compression ...

http://developer.android.com/guide/topics/resources/resources-i18n.html#CreatingResources "Note: Image resources placed in here may be automatically optimized with lossless image compression by the aapt tool. For example, a true-color PNG that does not require more than 256 colors may be converted to an 8-bit PNG with a color palette"

and from the aapt commandline "specify a pixel tolerance to force images to grayscale"

as to other opts ... ummm.

steelbytes