55

I recently updated the Android Studio to it's latest version, and now I am experiencing a headache with an exception in Gradle build.

Every time I run the project, two or three times before it succeed, I get the following error:

Gradle: Execution failed for task ': ProjectName:
mergeDebugResources'.
Java.lang.NullPointerException (no error message)

After trying again a couple times, the error does not happen again until the next run.

Does anybody have any idea of why this is happening? The project worked just fine 'til the update, never got any error before...

Thanks!

Android Developer
  • 987
  • 1
  • 8
  • 22
NOlivNeto
  • 703
  • 1
  • 5
  • 10

15 Answers15

52

It happens to me only when modifying the XML files on the project. If you rebuild the entire project before running (Build > Rebuild Project) it doesn't show up anymore.

René M
  • 698
  • 1
  • 5
  • 5
32

inside your project directory, run:

./gradlew clean build

or from Android Studio select:

Build > Clean Project

Updated: As @VinceFior pointed out in a comment below

João M
  • 1,939
  • 21
  • 14
19

You may have a corrupted .9.png in your drawables directory

Andi F.
  • 717
  • 5
  • 7
  • My issue was fixed after reading your comment. I think exception is common for multiple issues. – AndroDev Jan 27 '17 at 08:44
  • i found same issues, i removed corrupted png file and file > invalidate caches and restart. – yubaraj poudel Feb 12 '17 at 09:52
  • Even adding to app's gradle: `android { aaptOptions { cruncherEnabled = false}...` does not fix the problem since png files might be really corrupted: `AAPT err(Facade for 676904551): ERROR: 9-patch image \\?\C:\YouApp\app\src\main\res\drawable-xxxhdpi\yourimage.9.png malformed. AAPT err(Facade for 676904551): Frame pixels must be either solid or transparent (not intermediate alphas). AAPT err(Facade for 676904551): Found at pixel #395 along bottom edge.`. I regenerated png files at Tinypng.com and now it is building. – Junior Mayhé Jun 02 '17 at 15:40
16

This error could also happen if the generated build file path exceeds the windows max path length of 255 characters. Make sure your project path is not too long, use short names as well.

Rajesh
  • 191
  • 1
  • 8
12

I found a solution to the problem.

There is an issue reported about gradle build problems, it is not the same, but the solution seems to solve the mergeResourceDebug issues too. (issue here https://code.google.com/p/android/issues/detail?id=56158). In the comments it is stated that the solution is solved in Gradle 0.4.3.

To use Gradle 0.4.3, the build.gradle file needs to be updated manually. (Updating Android Studio does not change the build file)

Here is what I changed In build.gradle:

dependencies {
    classpath 'com.android.tools.build:gradle:0.4.3'
}

Since changing this, I have not seen any more mergeDebugResource issues when running my project. Hope this helps!

Edit: to stay up to date with Gradle you can change the version number to 0.4.+

Lorica
  • 136
  • 4
  • In my case it when doing so, it says : A problem occured while evaluating project. > Gradle version 1.6 is required. Current version is 1.8. – Vishwas Nov 27 '13 at 16:28
  • I already have such a line in my build.gradle (the one in the project root), but the problem persists. And this is a brand new project in a fresh install. – Christofer Ohlsson May 04 '14 at 19:05
1

This would also happen if there is/are any additional folder/files in resource folder which are not supported by Android.

Vamsi Tallapudi
  • 3,633
  • 1
  • 14
  • 23
1

I had the same problem and managed to solve, it simply downgrade your gradle version like this:

dependencies {
    classpath 'com.android.tools.build:gradle:YOUR_GRADLE_VERSION'
}

to

dependencies {
    classpath 'com.android.tools.build:gradle:OLDER_GRADLE_VERSION_THAT_YOUR'
}

for example:

YOUR_GRADLE_VERSION = 3.0.0

OLDER_GRADLE_VERSION_THAT_YOUR = 2.3.2

Williaan Lopes
  • 1,177
  • 15
  • 11
0

In my case none of above works, I have just renamed the project name, everything works well.

Example:

My project name Before - sticky-headers-recyclerview-master

My project name After - SHRV

Hope this will help you.

Hiren Patel
  • 52,124
  • 21
  • 173
  • 151
  • in that case, you have simply followed [this previous answer](http://stackoverflow.com/a/18681672/1668057) – ljs.dev Apr 03 '16 at 01:53
0

My problem solve this one

compile fileTree(dir: 'libs', include: ['*.jar'])

to

provided fileTree(dir: 'libs', include: ['*.jar'])
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Mohan K
  • 1
  • 2
0

In my case, when I changed package name this issue appeared, I just followed below steps to fix my problem:

  1. Removed previously installed apk (uninstall)

  2. Applied project clean

  3. Run the app

Naveed Ahmad
  • 6,627
  • 2
  • 58
  • 83
0

Had to change build tools version from some old one in build.gradle for project module:

android {
    ...
    buildToolsVersion "24.0.2"
    ...
}
wieczorek1990
  • 7,403
  • 1
  • 25
  • 19
0

There is a new Gradle task called "cleanBuildCache" just run this task clean the cache then re-build the project.

huseyin
  • 1,367
  • 16
  • 19
0

In my case I just removed the space from project folder name From: MyApp latest

To: MyApp_latest

and it worked.

Said
  • 473
  • 7
  • 11
0

I just upgraded to the latest gradle build tool version and it works.

 classpath 'com.android.tools.build:gradle:3.0.1
Akash Bisariya
  • 3,855
  • 2
  • 30
  • 42
0

It could be a faulty name of a drawable file. I had an image I was using that was named Untitled. Changing the name solved my problem.