Ooba Elda
Ooba Elda

Reputation: 1672

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:

  1. Invalidate caches/restart
  2. Deleting gradle folder

Upvotes: 85

Views: 124868

Answers (24)

Gokulnath Thirukkamu
Gokulnath Thirukkamu

Reputation: 41

I too got this error. This issue is due to that jpeg or other format image is in .png extension. Try to replace the specific image with original png image. You can also change the format by uploading it to figma and export it to png. refer this image for issue

Upvotes: 1

Timo
Timo

Reputation: 165

Solution: I had the same issue working in macOS. Strangely it always came due to renaming a working .png file in the Finder. Simply changing the name of ic_launcher.png which worked as file to app_icon.png lead to a not working file. I worked around it by uploading the ic_launcher.png to a photo app like photopea and simply downloading it again to my computer under the new name app_icon.png.

Upvotes: 0

Baraiya Nayan
Baraiya Nayan

Reputation: 41

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 overwrite the old images and it works

enter image description here

Upvotes: 1

Halil Ozel
Halil Ozel

Reputation: 3332

I was getting the same error when signing APK.

This solution fixed the problem:

build.gradle(:app):

...
aaptOptions {
        cruncherEnabled = false
    }
...

You can check for more: https://developer.android.com/studio/build/optimize-your-build

Upvotes: 1

if you are facing this issue in Flutter while buildings apk then add crunchPngs false

android {
    buildTypes {
        release {
          ...
           crunchPngs false
        }
 }

into android/app/build.gradle

enter image description here

Upvotes: 3

Moustaoui Salaheddine
Moustaoui Salaheddine

Reputation: 78

Open [Root_project]/app/build.gradle and add following lines.

release {
          ...

            crunchPngs false // or true

            lintOptions {
                checkReleaseBuilds false
                abortOnError false
            }

          ...
}

Upvotes: 1

Diego Venâncio
Diego Venâncio

Reputation: 6027

Steps

  1. In build.gradle
aaptOptions {
    cruncherEnabled = false
}
  1. Delete content inside C:\Users\.gradle\caches (or ~/.gradle/caches for Mac and Linux)
  2. Restart Android Studio

Upvotes: 32

Kumar Santanu
Kumar Santanu

Reputation: 701

Failed to read PNG signature - Just put 1 line in your build.gradle

 buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        crunchPngs false  // Paste this line
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

Upvotes: 15

Mahdi-Malv
Mahdi-Malv

Reputation: 19270

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.

Upvotes: 154

Ucdemir
Ucdemir

Reputation: 3098

You can open the images with windows win10 'Paint', then you can save as .png and overrite it, It will solve the problem

Upvotes: -1

Joseph Ajibodu
Joseph Ajibodu

Reputation: 1676

I was able to fix it permanently.

I created a new blank expo project, then I added a new app icon (correct png format), then I ejected from expo.

I then copied the mipmap-* folders from the blank project to my real project. It all worked perfectly.

Upvotes: 0

Jameel Nazir
Jameel Nazir

Reputation: 276

You can add code in node_modules/react-native/react.gradle. After doFirst

doLast {
def moveFunc = { resSuffix ->
File originalDir = file("$buildDir/generated/res/react/release/${resSuffix}");
if (originalDir.exists()) {
File destDir = file("$buildDir/../src/main/res/${resSuffix}");
ant.move(file: originalDir, tofile: destDir);
}
}
moveFunc.curry("drawable-ldpi").call()
moveFunc.curry("drawable-mdpi").call()
moveFunc.curry("drawable-hdpi").call()
moveFunc.curry("drawable-xhdpi").call()
moveFunc.curry("drawable-xxhdpi").call()
moveFunc.curry("drawable-xxxhdpi").call()
moveFunc.curry("raw").call()
}

check it if it not fix issue after remove drawable folder github enter link description here

Upvotes: 0

Neetesh maurya
Neetesh maurya

Reputation: 81

In my case also there was a jpg file instead of png, so I changed my extension and solve my problem.

Upvotes: 1

paul
paul

Reputation: 479

If you are using an online platform to generate App Icon(launcher_icon), then use PNG Format or First convert JPEG to PNG and then used APP ICON GENERATOR

Upvotes: 1

BennyP
BennyP

Reputation: 1807

I had the same issue, solved by converting the images to webP from Android studio right-click on the image -> tap on Convert to WebP

the conversion will handle file formating and also reduce the size of the PNG

Upvotes: 2

parag barsar
parag barsar

Reputation: 31

I've had the same issue. To solve it just restart your Android Studio and build the gradle file again.

Upvotes: 1

Saqib Naseeb
Saqib Naseeb

Reputation: 741

This occurs due to the incorrect extension given to the image. For example, the image is jpg and the extension given is png.

Solutions:

  1. Add { cruncherEnabled = false } in build.gradle
  2. Convert the image into png rather than just changing the extension.

Upvotes: 3

Keshav Gera
Keshav Gera

Reputation: 11264

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'
        }
    }

Upvotes: 33

Vikas V Shastry
Vikas V Shastry

Reputation: 75

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.

Upvotes: 1

Varun Barve
Varun Barve

Reputation: 323

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

Upvotes: 1

Prinkal Kumar
Prinkal Kumar

Reputation: 3326

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 }

Upvotes: 1

Firze
Firze

Reputation: 4049

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.

Upvotes: 1

Jorgesys
Jorgesys

Reputation: 126563

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.

Upvotes: 5

Ooba Elda
Ooba Elda

Reputation: 1672

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.

Upvotes: 0

Related Questions