Android Studio - mergeDebugResources exception

AndroidGradleAndroid Studio

Android Problem Overview


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 Solutions


Solution 1 - Android

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.

Solution 2 - Android

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

Solution 3 - Android

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

Solution 4 - Android

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.

Solution 5 - Android

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.+

Solution 6 - Android

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

Solution 7 - Android

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

Solution 8 - Android

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.

Solution 9 - Android

My problem solve this one

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

to

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

Solution 10 - Android

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

Solution 11 - Android

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

android {
    ...
    buildToolsVersion "24.0.2"
    ...
}

Solution 12 - Android

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

Solution 13 - Android

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

To: MyApp_latest

and it worked.

Solution 14 - Android

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

 classpath 'com.android.tools.build:gradle:3.0.1

Solution 15 - Android

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNOlivNetoView Question on Stackoverflow
Solution 1 - AndroidRené MView Answer on Stackoverflow
Solution 2 - AndroidJoão MView Answer on Stackoverflow
Solution 3 - AndroidAndi F.View Answer on Stackoverflow
Solution 4 - AndroidRajeshView Answer on Stackoverflow
Solution 5 - AndroidLoricaView Answer on Stackoverflow
Solution 6 - AndroidVamsi TallapudiView Answer on Stackoverflow
Solution 7 - AndroidWilliaan LopesView Answer on Stackoverflow
Solution 8 - AndroidHiren PatelView Answer on Stackoverflow
Solution 9 - AndroidMohan KView Answer on Stackoverflow
Solution 10 - AndroidNaveed AhmadView Answer on Stackoverflow
Solution 11 - Androidwieczorek1990View Answer on Stackoverflow
Solution 12 - AndroidhuseyinView Answer on Stackoverflow
Solution 13 - AndroidSaidView Answer on Stackoverflow
Solution 14 - AndroidAkash BisariyaView Answer on Stackoverflow
Solution 15 - Androiduser10851318View Answer on Stackoverflow