androidnine-patch

Standard 9 patch generator for shadows produces 9 patches which won't compile


I've been trying to use this http://inloop.github.io/shadow4android/, but all the 9 patches it draws won't compile with Android studio. Anyone have a fix or an alternative? I'm trying to draw shadows.

AAPT: error: file failed to compile.

When I look at the 9 patch editor in Android Studio it doesn't show any bad patches.

I need to control the color of the shadow and I'm using a Cardview.


Solution

  • I generated a 9-patch on the site you mentioned. In Android Studio I see this error:

    AAPT: error: found an invalid color.
    ...path to directory...
    shadow_95536.9.png: error: file failed to compile.

    The following error is seen when running aapt directly:

    aapt c -S . -C .\tmp
    Crunching PNG Files in source dir: .
    To destination dir: .\tmp
    ERROR: 9-patch image shadow_95536.9.png malformed.
    Frame pixels must be either solid or transparent (not intermediate alphas).
    Found at pixel #26 along bottom edge.

    Upon inspection in an image editor, it becomes clear that there is a pixel in the bottom of the image that has an alpha other than completely opaque or transparent as stated in the aapt error message. Deleting the offending pixel by making it 100% transparent solved the compile problem.

    enter image description here

    If this is the issue that you are seeing, inspect the borders of the 9-patch in an image editor of your choice (I use GIMP) and correct the offending pixel(s).