Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

android - Failed to read PNG signature: file does not start with PNG signature

Gradle build failing with this error:

Error:C:UsersRoman.gradlecachesransforms-1files-1.1appcompat-v7-26.0.2.aarab547c3f1b8061ef9426f524a823a15
esdrawable-xhdpi-v4abc_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:devworkspaceandroid2MatrixCalculatorappuildintermediates
esmergeddebug C:UsersRoman.gradlecachesransforms-1files-1.1appcompat-v7-26.0.2.aarab547c3f1b8061ef9426f524a823a15
esdrawable-xhdpi-v4abc_btn_switch_to_on_mtrl_00001.9.png
Issues:
 - ERROR: C:UsersRoman.gradlecachesransforms-1files-1.1appcompat-v7-26.0.2.aarab547c3f1b8061ef9426f524a823a15
esdrawable-xhdpi-v4abc_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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Perhaps it's not actually a PNG, but a JPG renamed to PNG.
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...