6

I replaced the default logo files "ic_launcher.png" in the different dpi folders with my own files, also named "ic_launcher.png", but now I'm getting this error:

Error: failed to read PNG signature: file does not start with PNG signature

when generating apk, on all the 5 files I replaced in the mipmap folders

How do I fix that?

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
Abhijeet
  • 345
  • 1
  • 4
  • 15

5 Answers5

9

When you create the .apk all the resources are analyzed and if you get the error message:

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

enter image description here

This error is caused because your resource is not really a .png image, the format is incorrect, the file is corrupt or the .png file is really a vector asset.

enter image description here

you can check it by opening your file.

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
  • 1
    if image name has a number it will be a problem. for example if copy/pasted outside the android studio. this problem can not be recognized by android studio – mehmet May 19 '18 at 11:36
3

Yeah me too got this error but you can fix this by choosing refactor>rename and rename the extension into .jpg instead of .png and refactor it that's all.. and you will be not getting error anymore

Harsh Kothari
  • 439
  • 4
  • 8
0

Run these two commands and see if there are any errors..

  1. ionic cordova resources android --icon
  2. ionic cordova resources android --splash

If you get any error.. it means your icon and splash's png dimension is wrong. So correct it and then again run these two commands.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
0

This error is caused by the launcher icon (maybe it is corrupt), please check first your launcher icon & then generate signed apk.

1737973
  • 159
  • 18
  • 42
0

I had the same issue error loading .png in Xamarin forms (android). The same trick fixed the issue by renaming the png as .jpg and changing the code accordingly to point to jpg instead of png.

<Image HeightRequest="200" WidthRequest="200" Source="logo.jpg"/>

That said I don't think the problem is that file format was incorrect, something is probably wrong elsewhere. For example I had created the png file using MS Paint and pasted the image into it. It should be correct png file and it does open fine in picture editors as well as visual studio.

Weird solution.

p.s

When you rename the png, you will need to delete the existing png resource from project, rename the file in explorer and add the resource again in (Visual Studio 2019) project.

zar
  • 11,361
  • 14
  • 96
  • 178