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:29

This is a result of wrong file type indeed and can be fixed by saving the files in correct format.

I ran into this issue with PhoneGap Build and wanted to leave my 2 cents for any other PhoneGap / Cordova user who might also run into this.

My problem was that I upgraded my old PhoneGap 6.x to 8.0 and it seems behaviour of the default splash has changed. It used to require jpg as a default splash, but on 8.0 it results in this error on production builds.

This worked before:

<splash src="www/splash.jpg" />

Now you have 2 options. Replace the default splash with png like this:

<splash src="www/res/screen/android/screen-xhdpi-portrait.png" />

Other option is to remove default splash entirely.

查看更多
我命由我不由天
3楼-- · 2019-04-08 09:30

The problem might 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.

查看更多
仙女界的扛把子
4楼-- · 2019-04-08 09:30

i have same error for slow i do some step:

  1. open abc_btn_switch_to_on_mtrl_00001.9.png (Image)file in paint
  2. now select png and save as and re-save in drawable and overweight in with old images and its work

enter image description here

查看更多
登录 后发表回答