103

I've added some pictures with the format *.png to my drawable-directory and linked it with the layouts. But every time when I tried to build it, there appears an error

"...Crunching Crunsher ...png failed"

Following is the output of the console:

app:mergeDebugResources
AAPT out(1561599) : No Delegate set : lost message:Done
AAPT out(12956469) : No Delegate set : lost message:Done
AAPT out(20612543) : No Delegate set : lost message:Crunching             C:\Dev\StudioProjects\test\android\app\src\main\res\drawable\bt_meeting_focused.png
AAPT out(11030156) : No Delegate set : lost message:Crunching     C:\Dev\StudioProjects\test\android\app\src\main\res\mipmap-mdpi\ic_launcher.png
AAPT out(11030156) : No Delegate set : lost message:Crunching single PNG file: C:\Dev\StudioProjects\test\android\app\src\main\res\mipmap-    mdpi\ic_launcher.png
AAPT out(11030156) : No Delegate set : lost message:    Output file:     C:\Dev\StudioProjects\test\android\app\build\intermediates\res\debug\mipmap-mdpi-v4\ic_launcher.png
AAPT out(11030156) : No Delegate set : lost message:Done
AAPT err(11030156): libpng error: Not a PNG file
AAPT out(20612543) : No Delegate set : lost message:Crunching single PNG     file:     C:\Dev\StudioProjects\test\android\app\src\main\res\drawable\bt_meeting_focused.png
AAPT out(20612543) : No Delegate set : lost message:    Output file:     C:\Dev\StudioProjects\test\android\app\build\intermediates\res\debug\drawable\b    t_meeting_focused.png
AAPT out(20612543) : No Delegate set : lost message:Done
AAPT err(20612543): libpng error: Not a PNG file
AAPT err(1561599): libpng error: Not a PNG file
AAPT err(12956469): libpng error: Not a PNG file

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Crunching Cruncher uhr.png failed, see logs

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --    debug option to get more log output.

BUILD FAILED

Total time: 14.598 secs
Executing tasks: [clean, :app:generateDebugSources,     :app:generateDebugAndroidTestSources]

Configuration on demand is an incubating feature.
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportSupportV42220Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
AAPT out(14080484) : No Delegate set : lost message:Done
AAPT out(9206750) : No Delegate set : lost message:Done
AAPT out(25360025) : No Delegate set : lost message:Done
AAPT err(25360025): libpng error: Not a PNG file
AAPT err(14080484): libpng error: Not a PNG file
AAPT out(6423170) : No Delegate set : lost message:Crunching C:\Dev\StudioProjects\test\android\app\src\main\res\drawable\anfrage_senden_.png
AAPT err(6423170): libpng error: Not a PNG file
AAPT out(6423170) : No Delegate set : lost message:Crunching single PNG file:     C:\Dev\StudioProjects\test\android\app\src\main\res\drawable\anfrage_senden_.png
AAPT out(6423170) : No Delegate set : lost message: Output file: C:\Dev\StudioProjects\test\android\app\build\intermediates\res\debug\drawable\a    nfrage_senden_.png
AAPT out(6423170) : No Delegate set : lost message:Done
AAPT err(9206750): libpng error: Not a PNG file

Process list not empty
:app:mergeDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Crunching Cruncher uhr.png failed, see logs

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --    debug option to get more log output.

BUILD FAILED

Total time: 4.325 secs

I tried to clean the project, rebuild it, refresh the dependencies via "gradlew clean build --refresh-dependencies", nothing worked. I've checked the dependencies in the build.gradle file but nothing seems creating the error.

   apply plugin: 'com.android.application'
   android {
   compileSdkVersion 22
   buildToolsVersion "22.0.1"
   compileOptions.encoding = 'windows-1251'

   defaultConfig {
       applicationId "com.example.benutzer.test"
       minSdkVersion 16
       targetSdkVersion 22
       versionCode 1
       versionName "1.0"
   }
   buildTypes {
    release {
           minifyEnabled false
           proguardFiles getDefaultProguardFile('proguard-android.txt'),    'proguard-rules.pro'
       }
   }
   }

   dependencies {
   compile 'com.android.support:support-v4:22.2.0'
  }

Do you've got an idea, what's the source of the error? The filepath is also not too long and everytime unter 256 signs, that also not the problem :/

Thank you in advance :)

Abhishek T.
  • 1,133
  • 1
  • 17
  • 33
bot.rubiks
  • 1,031
  • 2
  • 7
  • 5
  • have you had any further luck on this? I am experiencing the same. – mushcraft Jun 19 '15 at 20:09
  • 1
    I already solved this issue by sharing the solution here --> http://stackoverflow.com/questions/22583418/execution-failed-for-task-appmergedebugresources-android-studio/36276670#36276670 – ashumeow Mar 29 '16 at 06:15
  • 2
    Error: File path too long on windows, keep below 240 characters Just try to use shorter path for your project. In my case i have moved my project source from other folder to desktop and after opening project from desktop this problem solved automatically. – Lucky Rana Sep 23 '16 at 02:49
  • @LuckyRana same worked for me – Bassem Wissa Jan 18 '17 at 09:10
  • As @LuckyRana said , less number of characters matters , i did not have to change the directory , my project name was too long , so made it shorter and it worked . This might help if someone faces the issue and their project is already in a root directory . – devcodes May 23 '17 at 04:33
  • This might help or not (a bit similar messages): https://stackoverflow.com/a/43686955/529442 – Eugene Gr. Philippov Sep 13 '17 at 11:48
  • Possible duplicate of [Error:Execution failed for task ':app:mergeDebugResources'. > Some file crunching failed, see logs for details build gradle issues](https://stackoverflow.com/questions/37131212/errorexecution-failed-for-task-appmergedebugresources-some-file-crunchin) – shadygoneinsane Sep 30 '17 at 10:13
  • Error was using psd file in drawable. I removed it and it worked – iamnaran Apr 12 '18 at 10:55

33 Answers33

128

In my case, the error was caused by a PNG file I added to the drawable folder. I had changed its extension from jpg to png by changing the text (in an inproper way) and then uploading it as PNG.

This was the problem Android Studio was pointing to.

I fixed this problem and got the error to disappear by changing the file extension using the Paint.NET tool or any other tool (proper way), and then uploading it to the drawable folder.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
smoothumut
  • 3,423
  • 1
  • 25
  • 35
  • 13
    Tip: if you are on mac os you can open the terminal and run the following command from images folder: 'sips -s format png *.png --out .' It will properly convert all the files with .png sufix into real PNG files :) – cassioso Jun 14 '16 at 04:08
  • same thing happened to me I renamed an extension too from psd to png and it failed to run. got this exact error message. – TharakaNirmana Jul 19 '16 at 13:38
  • 2
    This issue reproduced for me as well. Much thanks for your answer. – Nisim Naim Dec 21 '16 at 08:46
  • @cassioso Thanks buddy. – WideFide Feb 27 '17 at 18:42
  • Our artist send me images with a .png extension but when viewed in Android Studio I could see they were .PSD format. The amazing sips command from cassioso fixed the files. 'sips -s format png *.png --out .' – pzulw Apr 18 '17 at 13:28
  • 1
    Thanks buddy.. resolved my issue by doing exactly the same u mentioned. – Aparna May 12 '17 at 22:45
116

I fixed this issue by moving the project to the outer directory, and it then compiled successfully.

It was due to the long path of the project directory.

For example, I moved the project from:

D:/Android/Apps/AndroidStudioProject/AppName

to

D:/Android/AppName
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Lakhan Sharma
  • 1,741
  • 1
  • 12
  • 19
53

This is due to adding an image in drawable which has some extension like (.jpg), and you have changed or saved that to a .png format (this error will occur while changing the image format manually without using an editor tool).

Android Studio will throws an error while compiling the resource package using AAPT (Android Asset Packaging Tool), so all you need to do is use some image editor tools like GIMP or Paint to save the extension accordingly. Rebuild your project once everything is done.

For example: open your image in Paint (drag and drop your image to open it) → menu FileSave AsSave as Type → select your required type from the dropdown like I have shown in the below pictures:

Enter image description here

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
anand krish
  • 4,281
  • 4
  • 44
  • 47
20

In my case the solution was simple. I moved the entire project to another location where the path is short.

The problem was caused by long directory names and file names.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kadir Erturk
  • 583
  • 6
  • 8
  • 5
    The OP does say that the file path is not to long. If you want to challenge him on that perhaps a comment would be better. – Jonathan Mee Oct 27 '16 at 17:56
  • This has to do with Windows path length limits when Bamboo is running on Windows Server. Solution: Build on Linux! – Ewoks Feb 01 '17 at 15:03
20

The best solution is to change buildDir in build.gradle:

For example:

allprojects {
    buildDir = "C:/tmp/${rootProject.name}/${project.name}"
    repositories {
        jcenter()
    }
}

Rebuild and happy coding.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Heberth
  • 615
  • 6
  • 16
  • Much easier than moving the project. Nice! – fishjd Mar 17 '17 at 19:16
  • Tried the solution and it worked but now i cant deploy to my phone from Visual Studio 2015. Get the following error "Could not locate a deployable apk. You may need to build your project." – Hassan Ata Ullah Jan 19 '18 at 10:15
9

In my case, I solved this problem by simply changing my library file as I made a silly mistake of adding two different versions of the same library.

As this can be due to varied reasons, I found out the following ways to solve this issue as per the problem:

  1. Mismatch of resources

  2. Missing attributes, wrong tags, etc. in resources

  3. Issue in styles

  4. Missing name in styles

  5. Duplicacy of resources and libraries

  6. Sometimes it can even be solved by changing the compatible library in build.gradle

  7. Executing the aapt command

  8. Renaming the extension from .jpg to .png

  9. Simply with the help of Clean Project.

    1. Even in some cases, restarting Android Studio can solve the problem.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SID --- Choke_de_Code
  • 1,131
  • 1
  • 16
  • 41
4

This is because your PNG file is not supported or else you renamed your file directly.

Do the following steps.

  1. Copy your image source file from Android Studio to your desktop.
  2. Open the file with Paint.
  3. Save file as extension .png
  4. Delete the existing source file from Android Studio which you copied.
  5. Add the newly created file which you renamed via Paint.

Problem solved :)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Learning Always
  • 1,563
  • 4
  • 29
  • 49
4

In my case, when I created a 9.png file, my original PNG file was using the margin where the 9.png line is drawn, creating a bad 9.png file. Try to add some margin to your PNG file.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Guilherme Ramos
  • 196
  • 2
  • 10
  • Yes mine was similar to this. I was altering an image file and when I saved it, it became corrupt. I just had to redo the adjustments to the image and resave it. – uplearned.com Apr 27 '17 at 05:19
4

If you're running Linux, try this:

sudo apt-get install lib32stdc++6 lib32z1

It is from here.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Maksim Turaev
  • 4,115
  • 1
  • 29
  • 42
3

The best answer is already given in the gradle output:

* Try:
Run with --stacktrace option to get the stack trace. 

Open the Terminal in Android Studio and run gradlew :app:mergeDebugResources --stacktrace. (In my case it was the Windows 240 char limit), but it should give you the root cause for any other issue just as well.

mattlaabs
  • 486
  • 3
  • 14
3

In my case, I believe this issue was to do with the length of the file path. UNIX and Windows systems impose a maximum path length of 255 and 260 characters respectively, and I believe the crunch process fails when assigning to a dynamically-specified path. So, even if the quoted path lengths in the error message are shorter than the limit (mine was only 187 within a Windows build environment), I think the crunch utility may internally specify a longer path, even if just temporarily.

You may determine whether this is the source of error by moving your project to the root-most directory on your file system, then attempt recompiling.

Mapsy
  • 4,192
  • 1
  • 37
  • 43
  • Thank you. I had the same problem but did not realize it. The error message did not indicate path length as the problem and the length of the path to the file it prints was well under 255. Nevertheless, setting an env var GRADLE_USER_HOME to something very short fixed the issue on my build machine. – albert c braun Mar 17 '18 at 02:45
2

I noticed downgrading Gradle build tools to 1.2.3 solved my problem of the Crunching PNG error, but on 1.5.0 the problem continues.

AskQ
  • 4,215
  • 7
  • 34
  • 61
2

I tried to rebuilt, restart, clean, update Gradle, etc. However, none of them worked for me.

Sometimes, it can be caused by a wrong naming for an XML or resource file.

At least, for me, that problem was solved by changing the name.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
elifekiz
  • 1,456
  • 13
  • 26
1

I had put my images into my drawable folder at the beginning of the project, and it would always give me this error and never build so I:

  1. Deleted everything from drawable
  2. Tried to run (which obviously caused another build error because it's missing a reference to files
  3. Re-added the images to the folder, re-built the project, ran it, and then it worked fine.

I have no idea why this worked for me, but it did. Good luck with this mess we call Android Studio.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rychrist88
  • 643
  • 6
  • 14
1

The Crunching process is the image preparation process, which means something is wrong with your image files. In my case I had a PNG file which was not really a PNG file.

My solution:

I converted all my images to PNG running a super simple Python script from within the image folder, so in total all you need to do is:

  1. In order to install the PIL library, run: pip install pillow

  2. Save the below Python code in a .py file within your images folder you want to convert.

  3. Adjust the from_format, to_format variables in the script to whatever you need.

  4. Run script: python script_name.py

    import os
    from PIL import Image
    
    from_format = (".jpg", ".png", ".bmp")
    to_format = "png"
    
    for fn in os.listdir('.'):
         if os.path.isfile(fn) and fn.lower().endswith(from_format):
            print "Converting File: %s" % fn
            im = Image.open(fn)
            im.save(fn.split('.')[0] + '.' + to_format, to_format.upper())
    

And if you want read more about the Image module: http://effbot.org/imagingbook/image.htm

Community
  • 1
  • 1
Mercury
  • 7,430
  • 3
  • 42
  • 54
1

I faced this problem when I copied my images (no matter JPEG or PNG) into the drawable folder manually. There might be different kinds of temporary solutions to this problem, but one best eternal way is to use the Drawable importer plugin for Android studio.

Install it by going to: menu FileSettingsPluginsBrowse Repositories → search "Drawable". You'll find Drawable importer as the first option. Click install on the right panel.

Use it by right clicking on the Drawable resource folder and then new. Now you can see four new options added to the bottom of the list, and among those you will find your appropriate option. In this case the "Batch drawable import" would do the trick.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AmiNadimi
  • 5,129
  • 3
  • 39
  • 55
1

I changed the location of the app and copied it to a short path. You can do that by just copying your project and pasting it to a new Short Location. And, it worked for me.

For example,

Old_path: c/:user/android_studio_project/your_app
New_path: c/:your_app
Crime_Master_GoGo
  • 1,641
  • 1
  • 20
  • 30
1

I got this issue after migration to Gradle 3.3, on Windows (with gradle-2.14.1 everything was fine).

The problem was in the path to the Gradle build-cache, which contains Cyrillic characters, like

C:\Users\Иван\.android\build-cache

So I renamed the user's folder to "Ivan", and the problem was gone.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
IvanP
  • 1,064
  • 13
  • 16
1

It seems to be a nasty problem of Gradle. We just upgraded from 2.14 to 3.3 and our build server couldn't build any more (a local build in Android Studio worked).

Error with too long path shows for example:

C:\Windows\System32\config\systemprofile.gradle\caches\3.3\scripts-remapped\build_bonsjy48fqq8sotonpgrvhswt\36ejadunoxgw3iugkh95lqw\projedd7e29570ae79482d0308d82f4e346b\classes\build_bonsjy48fqq8sotonpgrvhswt$_run_closure1$_closure8$_closure13$_closure14$_closure15.class

We had to create a local user account for the service that ran as system service for years... Now it saves under C:\Users... which is much shorter as the system profile path.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
The incredible Jan
  • 741
  • 10
  • 17
1

File > Invalidate Caches / Restart

User
  • 4,023
  • 4
  • 37
  • 63
0

Closing Android Studio and opening again solved this issue in my case.

Give it a try. I know it is not the right solution or answer, but it works. I am not sure about the root cause. It would be great if someone can share that.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sunil Purushothaman
  • 8,435
  • 1
  • 22
  • 20
0

I was importing an Android application in Android Studio (Gradle version 2.10) from Eclipse. The drawable images are not supported, then manually remove those images and paste some PNG images.

And also update the Android drawable importer from the Android repository. Then clean and rebuild the application, and then it works.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Murugesan
  • 43
  • 7
0

This error was caused for me because of the path where my project was located. There was a blank space in one folder, for example,

Folder\Another Folder\MyAndroidProjects\...

Changing it to Folder\AnotherFolder\MyAndroidProjects\... and resynchronising Gradle resolved this for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Marcus
  • 6,697
  • 11
  • 46
  • 89
0

I have faced this problem also, and it has not been solved by reformatting the image although it was an image from a project app of Google, and it was only solved by:

Moving the project file to the partition directly

Try it. It might help you.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dasser Basyouni
  • 3,142
  • 5
  • 26
  • 50
0

In my case I reached the solution in two steps:

  1. Keep your project name, package name, folder names short, because if the directory name exceeds 255 characters it gives the mergeResource error.
  2. Keep your drawables in the drawable folders. Any drawable file such as .jpg and .png outside the drawable folders throws the mergeResource folder error.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
DiRiNoiD
  • 1,281
  • 2
  • 18
  • 24
0

I am also suffering from the same issue. In my case I just copied the image to the drawable folder, then Android Studio is showing the error "Some file crunching failed".

My problem regarding to image only because that image was saved from the one of the my customized camera application in .png format. And for testing purposes I copied it into the drawable folder.

After that I tested saving the image as .jpg. It was not giving any error. That means the camera by default supports the ".jpg" format.

Finally I realized two things:

  1. The camera by default supports the ".jpg" format

  2. Without using image tools, don't change the image formats (even programmatically).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kona Suresh
  • 1,836
  • 1
  • 15
  • 25
  • file extension != file format You can name a file like you want - it won't change it's format. – The incredible Jan Mar 10 '17 at 10:46
  • I am not understanding what you trying to say!. My image taken from the custom camera app and saved as .png programmatically. So when I add that image to drawable folder compilation was fail. when save the image from my camera app as .jpg it won't give the error. – Kona Suresh Mar 10 '17 at 11:01
  • I understood your answer like this: your app created a jpg but named it "png" and then you were surprised that it didn't work. – The incredible Jan Mar 28 '17 at 13:58
0

Just add this to your local.properties file of your project:

BUILD_DIR=C\:\\Tmp

(The error in Windows is due a long path, so I gave the path to one temporary folder.)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
RATHI
  • 5,129
  • 8
  • 39
  • 48
0

For me, it is because one of my .png files is actually a .psd file. Resave it to real PNG file, and it is fixed.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kai Wang
  • 3,303
  • 1
  • 31
  • 27
0

For me, it was a corrupted PNG file.

Go to your res folder and try to open every image. When you find an image which can't be opened, replace it with a good image.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Floris M
  • 1,764
  • 19
  • 18
0

It took a lot of investigation to figure this out, but the root cause of this issue, in my case, turned out to be that the processor of my dev machine is no longer supported by Android Studio. Please see this this issue for more details.

The issue manifests itself as errors related to *.9.png files, but in reality the problem is that Android Studio no longer works on processors that don't support SSSE3 instructions (AMD Phenom, Athlon and older processors, for instance). There doesn't seem to be any workaround at this time.

Vijayendra Vasu
  • 271
  • 3
  • 7
0

As this can be cause by many different issues for me it was in several layout files I had defined the layout_width and layout_height in the parent layout and the actual implementing layout below.

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:bind="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

Best way to find out is running gradle manually with a Stacktrace

Sn0wfreeze
  • 1,959
  • 3
  • 18
  • 32
-1

To solve this problem you should use drawable -> new -> image asset and then add your images. You will then find the mipmap folder contains your images, and you can use it by @mibmab/img.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
-2
  1. Look at the folders drawable-hdpi, drawable-mdpi, drawable-xhdpi and so on.
  2. If there is a wrong bitmap file, Delete it and resave.
  3. Go to Build->Rebuild Project
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
brian
  • 289
  • 3
  • 3