Failed to read PNG signature: file does not start with PNG signature
Gradle build failing with this error:
Error:C:\Users\Roman\.gradle\caches\transforms-1\files-1.1\appcompat-v7-26.0.2.aar\bab547c3f1b8061ef9426f524a823a15\res\drawable-xhdpi-v4\abc_btn_switch_to_on_mtrl_00001.9.png failed to read PNG signature: file does not start with PNG signature
Error:java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.internal.aapt.AaptException: AAPT2 compile failed:
Error:Execution failed for task ':app:mergeDebugResources'.
Error: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.internal.aapt.AaptException: AAPT2 compile failed:
aapt2 compile --legacy -o C:\dev\workspace\android2\MatrixCalculator\app\build\intermediates\res\merged\debug C:\Users\Roman\.gradle\caches\transforms-1\files-1.1\appcompat-v7-26.0.2.aar\bab547c3f1b8061ef9426f524a823a15\res\drawable-xhdpi-v4\abc_btn_switch_to_on_mtrl_00001.9.png
Issues:
- ERROR: C:\Users\Roman\.gradle\caches\transforms-1\files-1.1\appcompat-v7-26.0.2.aar\bab547c3f1b8061ef9426f524a823a15\res\drawable-xhdpi-v4\abc_btn_switch_to_on_mtrl_00001.9.png failed to read PNG signature: file does not start with PNG signature
Some basic things i've tried to solve this issue:
- Invalidate caches/restart
- Deleting gradle folder
Solution 1:
It's likely a JPG
renamed to a PNG
file, not an actual PNG file
The problem could be because of the wrong extension of images.
In my case, the file was a JPEG
image but it was saved as PNG
not converted to. In this situation change extension to the real one and convert to PNG then retry.
For instance, you have ic_logo.png
but it's actually a JPG image.
You should rename it back to ic_logo.jpg
and use something like Photoshop to convert the image to PNG format.
Solution 2:
Steps
-
In
build.gradle
aaptOptions { cruncherEnabled = false }
Delete content inside
C:\Users\.gradle\caches
- Restart Android Studio
Solution 3:
android {
buildTypes {
release {
crunchPngs false // or true
}
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
crunchPngs false // or true
lintOptions {
checkReleaseBuilds false
abortOnError false
}
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}