52

I have this error when trying to make a module of a project

apply plugin: 'com.android.library'

android {
    compileSdkVersion 17
    buildToolsVersion "19.1.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 8
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile files('libs/sdk.jar')
    compile files('libs/ads-lib.jar')
    compile project(':google-play-services_lib')
    compile files('libs/hdvdecoderandroid.jar')
}

How can i fix this error?

Edit

Here is my logs file, when i try to build it in command line

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':hDVietAndroid:m
ergeDebugResources'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAct
ions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(Ex
ecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.exe
cute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(Skip
UpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(Valida
tingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.exec
ute(SkipEmptySourceFilesTaskExecuter.java:42)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute
(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOn
lyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute
(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(Abstra
ctTask.java:305)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.ex
ecuteTask(AbstractTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.pr
ocessTask(AbstractTaskPlanExecutor.java:63)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.ru
n(AbstractTaskPlanExecutor.java:51)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPla
nExecutor.java:23)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGr
aphExecuter.java:88)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutio
nAction.java:29)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:6
2)
        at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.jav
a:23)
        at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java
:68)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionA
ction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:6
2)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:5
5)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLa
uncher.java:149)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher
.java:106)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.jav
a:86)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.
run(InProcessBuildActionExecuter.java:80)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildA
ctionExecuter.java:36)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildA
ctionExecuter.java:26)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(
CommandLineActionFactory.java:237)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(
CommandLineActionFactory.java:210)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValida
tionAction.java:35)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValida
tionAction.java:24)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandL
ineActionFactory.java:206)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandL
ineActionFactory.java:169)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAc
tion.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAc
tion.java:22)
        at org.gradle.launcher.Main.doAction(Main.java:33)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.jav
a:54)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: java.lang.RuntimeException: Crunching Cruncher vertbar.9.png failed, see logs

        at com.android.builder.png.QueuedCruncher.waitForAll(QueuedCruncher.java:178)
        at com.android.builder.png.QueuedCruncher.end(QueuedCruncher.java:190)
        at com.android.ide.common.res2.MergedResourceWriter.end(MergedResourceWriter.jav
a:128)
        at com.android.ide.common.res2.DataMerger.mergeData(DataMerger.java:291)
        at com.android.ide.common.res2.ResourceMerger.mergeData(ResourceMerger.java:48)
        at com.android.build.gradle.tasks.MergeResources.doFullTaskAction(MergeResources
.groovy:112)
        at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(Incrementa
lTask.groovy:70)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$I
ncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:235)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$S
tandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$I
ncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:222)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$S
tandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAct
ion(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAct
ions(ExecuteActionsTaskExecuter.java:61)
        ... 47 more

I try to search in stackoverflow, but i can't find a correct answer for my case.

mr.icetea
  • 2,607
  • 3
  • 24
  • 42

22 Answers22

35

As stated here this can happen when using the Gradle Tools v1.1.0. After updating to v1.1.3, this has not happened anymore.

Niklas
  • 23,674
  • 33
  • 131
  • 170
  • @muetzenflo yup I also had the problem only on our Jenkins Server. However with v1.1.3 this seems to be fixed. – Niklas Apr 17 '15 at 22:50
  • Error:(48, 0) Gradle DSL method not found: 'classpath()' Possible causes: The project 'Sample' may be using a version of Gradle that does not contain the method – Prasad Feb 15 '16 at 04:48
  • 2
    According to link mentioned in the answer, I add `aaptOptions.setProperty("cruncherEnabled", false)` to build.gradle Android section. Everything ok. – einverne May 17 '16 at 09:40
  • Error:Execution failed for task ':(project name):mergeDebugResources'. > Some file crunching failed, see logs for details i am still getting this error – ajey Jul 11 '16 at 07:41
  • 5
    I'm having same problem with Gradle 2.2.3! – Fatima Dec 14 '16 at 12:57
30

Close android studio and open it again. Then try compiling the same code. I was getting the same error and it worked for me. Hope it helps.

Tejas Pawar
  • 690
  • 8
  • 16
19

It may happens because fake png files. You can use this command to check out fake pngs.

cd <YOUR_PROJECT/res/> && find . -name *.png | xargs pngcheck

And then,use ImageEditor(Ex, Pinta) to open fake pngs and re-save them to png.

Good luck.

Shengfeng Li
  • 606
  • 7
  • 11
  • Best answer, in my case I have a lot of resources and log doesn't give me the exact file, just seeking the corrupt png and saving it again saves me. Thanks – Leonardo Sapuy Jun 16 '16 at 16:08
  • 2
    This worked for me. If your using Mac you can brew install pngcheck. – Ivan Aug 29 '16 at 17:41
  • 'xargs' is not recognized as an internal or external command, – Iman Marashi Jan 15 '17 at 18:45
  • @Iman Marashi xargs is a command on Unix and most Unix-like operating systems used to build and execute command lines from standard input. Do you use the right operating systems. – Shengfeng Li Mar 02 '17 at 02:26
15

Ok, I just faced this problem and tried all of the steps mentioned above but didn't help. So what I did, I checked what image extension it was before I renamed it to .png. In my case it was .jpeg. So I renamed it back to .jpeg and kept the same original file in drawable. And bingo, it just worked fine.

So the solution is, use the file without changing extension, be it .png or .jpeg, keep it the original way.

Thought to share if it helps anyone. Thanks.

justLearning
  • 299
  • 2
  • 7
10

I have had this problem before with adding png files. I have discovered the problem with some of them since cleaning your project and closing AS does not solve every problem.

I did an experiment with GIMP when exporting images. Apparently, converting them to RGB fixes it. Some photos will be set to Indexed mode. Simply select Image>Mode>RGB. Then, export it and copy it into AS.

Daniel Mills
  • 160
  • 8
  • I found that the Image mode was already RGB but performing an export from GIMP did fix the issue thankfully. – the_new_mr May 13 '15 at 15:40
9

I was getting the same error and it worked for me. Hope it helps.

As Niklas said, you have to update to the latest Gradle version.


My way to solve the error:

  1. Open your Android Studio (AS) program.
  2. Go to your build.gradle file in your project.
  3. Change:

    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
    

    to:

    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.3'
    
  4. Sync your Android project with Gradle: enter image description here

  5. Clean your project.

  6. Rebuild your project.
  7. Done!

If its still not working:

  1. Close your Android Studio program and open it again.
  2. Try compiling the code.
  3. Done!

If you need more help, read the issue on Google Code!

Community
  • 1
  • 1
Suriyaa
  • 2,222
  • 2
  • 25
  • 44
  • 11
    same problem is coming in `'com.android.tools.build:gradle:1.5.0'` also – Kushal Feb 08 '16 at 06:54
  • 1
    Error:(48, 0) Gradle DSL method not found: 'classpath()' Possible causes: The project 'Sample' may be using a version of Gradle that does not contain the method. – Prasad Feb 15 '16 at 04:44
  • @Kushal Try to use older or newer versions of Gradle if Android Studio Gradle build is not working. See all previous versions in "Previous Releases" section in http://gradle.org/gradle-download/! – Suriyaa Feb 17 '16 at 17:04
6

After using pngcheck and resave all my image files to *.png, the problem still.

Finally, I found the issue is about *.9.png files. Open and check all your 9-Patch files, make sure that all files have black lines as below, if don't have, just click the white place and add it, then save it.

9-Patch

BobGao
  • 770
  • 8
  • 18
  • @Fakher I've tried all ways but still prompt the error, so I tried to compare the file which prompted in error message with other normal files, finally let me found out. – BobGao Feb 20 '17 at 09:54
  • Thats the only solution worked for me after working 2 hours on the same!!!Thanks @BobGao – Akash Bisariya Jun 07 '17 at 12:53
5

I had faced this similar error too. In my case it was one of my picture files in my drawable folder. Removing the picture that was unused solved the problem for me. So, make sure to remove any unused items from drawable folder.

karan
  • 8,637
  • 3
  • 41
  • 78
marin
  • 49
  • 1
  • 3
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). - [From Review](/review/low-quality-posts/10680538) – Dawood Awan Dec 25 '15 at 05:43
  • This does provide an answer, at least for me. @DawoodAwan, I know it's guidelines and everything but your comment comes off as pretty pedantic. More over when you request him to comment but doesn't have enough reputation to do so...go figure. – Sebastialonso Jan 21 '16 at 18:11
3

Additional to all answers, I think it could have similar problems. My Problem was caused by png.9 files. If this files, have a (in my case) too small stretching area with just a few pixels, the building failed with this error also. I have checked all these answers, but nothing helped. Giving a little bit bigger stretching area, solved the problem. I tested it many times, allways when I use small stretching areas it failed. So I am sure, it will help some poeple to make the stretch area a little bit bigger.

The second problem, but this is just an assumption, is the icon name (maybe only for png.9 files too). For examle, I used an image named folder_icon.9.png , with this one, it allways failed. Renaming it to other_folder_icon.9.png, it worked. So I think some names are used by the android system itself, maybe here is a problem too.

Opiatefuchs
  • 9,800
  • 2
  • 36
  • 49
3

I faced the same error but i solved this by selecting invalidate caches/restart option.

Click

  1. file >> invalidate caches/restart
yubaraj poudel
  • 3,821
  • 1
  • 31
  • 28
3

Sometimes, it can be caused by wrong naming for xml or resource file.

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

elifekiz
  • 1,456
  • 13
  • 26
2

Clean the project and build it again

Chatura Dilan
  • 1,502
  • 1
  • 16
  • 29
2

I came here because i had this problem and non of the answers here helped me. For future user that could be helped here:

My problem was I did two 9-patch images for a switch button. Then I rezized that image without 9-patching them. To solve the issue I had to 9-patch all the images for all the drawable folders (xxhdpi, xhdpi and so on)

rain_
  • 734
  • 1
  • 13
  • 24
1

The problem might probably be due to the mismatch of the extension types given by the programmer and the actual extensions of the images present in the drawable folder of your app. or fixing this follow the steps given below:-

Step 1- Double click on each of the image resources and and check the extension i.e whether the image is png or jpeg or any other format.

Step 2- Now check if the same extension is given by you in the drawable folder dropdown in package explorer(a.k.a Android in Android Studio).

Step 3 - If the extensions are not matching then delete that image and paste another image of the same name in its place making sure the extension is matching with the actual extension of the image (for example, if the image is "a.png" then make sure the extension of the image given by you is also of .png type) .

Step 4 - Sync your gradle file and run the project. This time there should be no errors.

1

Today I also met this problem. Here is how I solved it:

  1. I built the app, then I saw the errors in the message window. They said the picture (with the full path) was malformed.
  2. Then I found the malformed png which had the name xxx.9.png.
  3. I renamed it to xxx9.png and rebuilt. There were no errors, and the java files with the red wave under the name are gone too.
user2459500
  • 611
  • 5
  • 3
1

You can get this error if you have invalid 9-patch files. If there is anything apart from black and transparent in the border pixels you will get this error. The easiest way of fixing this is to open it up in Android Studio and modify the borders. Just adding and removing one pixel is enough.

It's worth noting that you won't see the bad pixels in AS, as the editor sets anything not black to transparent, but you will need to modify the file for it to save these changes.

TomW
  • 310
  • 1
  • 7
0

I had the same problem.

It was caused by a corrupted file. If you added some new Drawable before getting this error, check them to see if they are correctly display in Android Studio Viewer.

Sofiane Hassaini
  • 315
  • 3
  • 12
0

I have tried methods mentioned above, restarting the AS didn't work for me, and rebuilding didn't work either. Finally I found the problem was with the .9.png files, I deleted them and rebuilt the project, and it worked fine! Try it.

Mindjet
  • 51
  • 7
0

I had the same problem, but look at this image and I`m sure u can find the answer in such situation...the problem was in a png file. when I fixed what android studio asked me, it worked. I hope it works for U too. click this photo... it shows where is the problem and what it is

MNM
  • 1
0

I was also stuck by this problem.But in my case I delete all .png images from drawable folder ,clean and rebuild application and then paste all .png images to my drawable, rebuild again. It worked fine for me.

Sanoop Surendran
  • 3,484
  • 4
  • 28
  • 49
Uday Surse
  • 11
  • 4
0

Even i had same problem,this solution helped me so it might help you

check build version is matching with compile sdk version and add below code inside android block of build.gradle

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
hering
  • 1,956
  • 4
  • 28
  • 43
sneha v
  • 41
  • 6
0

This could also some extra reasons instead of the mentioned reasons :

  • You have a crashed image : one of your images cannot be load
  • adding an image to the drawable folder and modifying it's type (png ,jpg) while giving it a name(or inside the drawable folder using the rename function)
Achref Gassoumi
  • 1,035
  • 10
  • 20