Failed to read PNG signature: file does not start

2019-04-08 08:58发布

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:

  1. Invalidate caches/restart
  2. Deleting gradle folder

9条回答
成全新的幸福
2楼-- · 2019-04-08 09:16

For a quick fix ,Make shrinkResources to false instead of true in app.gradle Hope this will help. if Not then also add this aaptOptions { cruncherEnabled = false }

查看更多
闹够了就滚
3楼-- · 2019-04-08 09:17

I'm not sure if it's a valid solution, but deleting only the file mentioned in the error message helped. While deleting the folder, containing it didn't.

查看更多
我想做一个坏孩纸
4楼-- · 2019-04-08 09:20

Creating the .apk of an application all the resources are analyzed, if some resource has an incorrect format or is corrup you will get the message:

.png failed to read PNG signature: file does not start with PNG signature

enter image description here

Be sure to have the correct resources, you can check it by opening your file.

查看更多
迷人小祖宗
5楼-- · 2019-04-08 09:20

If you don't have any transparent pixels, then renaming the file to .jpg worked for me.

查看更多
姐就是有狂的资本
6楼-- · 2019-04-08 09:23

Steps

  1. In build.gradle

    aaptOptions { cruncherEnabled = false }

  2. Delete content inside C:\Users\.gradle\caches

  3. Restart Android Studio
查看更多
一夜七次
7楼-- · 2019-04-08 09:24

You might have used a JPEG file or some other image file format.

Use PNG images to solve the error.

Drawable directory can only have png type of images.

查看更多
登录 后发表回答