Maris B. Maris B. - 17 days ago 8
Android Question

Disable Android resource / image / png optimization

How to prevent the Android "build process" from optimizing .png images?

I have Android project with the following res directories:

- /res/
- /res/drawable
- /res/drawable-hdpi
- /res/drawable-hdpi-v5
- /res/drawable-ldpi
- /res/drawable-ldpi-v5
- /res/drawable-mdpi
- /res/drawable-mdpi-v5

These directories contain many .png files. I optimize PNGs sizes with PNGOUTWin, and overall size is reduced by more than 20%. When I build .apk file, the images are "optimized" by build process and overall size is now 10% above the initial size, or 30% above my/PNGOUTWin optimized size.

My goal is to reduce the .apk size, even if it will affect final performance, memory requirements, etc. How to prevent the "build process" from optimizing .png images?

I'm targeting Android 2.2 and above.

P.S. Currently building my Android project from the Eclipse, but will switch to the automated build later (Ant?)

Note about JPG images: JPG will not work because they do not have transparency.

Answer

As mentioned in the Android documentation : http://developer.android.com/guide/topics/graphics/2d-graphics.html#drawables

Note: Image resources placed in res/drawable/ may be automatically optimized with lossless image compression by the aapt tool during the build process. 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. This will result in an image of equal quality but which requires less memory. So be aware that the image binaries placed in this directory can change during the build.

So If you want to reduce the size of your application you should either reduce the color-depth of your PNG files (this helps a lot) or switch to .JPG files wherever possible.