Android Gradle Plugin (AGP) will automatically run PNG Crunch to losslessly compress PNG images during release builds of your app, as part of the AAPT2 packaging process.
In some cases, developers may end up with .png files that are actually JPEG files, or some other file type. When PNG Crunch attempts to compress these files, it will error and the build will fail. The error message will look something like this:
ERROR:/home/expo/workingdir/build/android/app/build/generated/res/createBundleReleaseJsAndAssets/drawable-mdpi/image.png: AAPT: error: file failed to compile.
To fix this, you can either delete the offending file, or convert it to a PNG file.
If you are already performing your own PNG optimization in advance of your build (which you may be doing in order to ensure the best possible compression and that the PNGs are also optimized for web and iOS), then running the files through PNG Crunch again may result in larger file sizes (source).
You can disable it by setting enablePngCrunchInReleaseBuilds
to false
on the android
config in expo-build-properties.
{
"name": "my-app",
"plugins": [
[
"expo-build-properties",
{
"android": {
"enablePngCrunchInReleaseBuilds": false
}
}
]
]
}
Alternatively, if you do not use CNG, you can make the following change to your android/app/build.gradle
file:
android {
// ...existing configuration
buildTypes {
release {
// ... existing configuration
pngCrunch false
}
}
}