[android] Android Studio - mergeDebugResources exception

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!

This question is related to android gradle android-studio

The answer is


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


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


My problem solve this one

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

to

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

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

To: MyApp_latest

and it worked.


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


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.


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

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

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

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

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


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.


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.


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


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.


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


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to gradle

Gradle - Move a folder from ABC to XYZ A failure occurred while executing com.android.build.gradle.internal.tasks Gradle: Could not determine java version from '11.0.2' Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0 Failed to resolve: com.android.support:appcompat-v7:28.0 Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0)

Examples related to android-studio

A failure occurred while executing com.android.build.gradle.internal.tasks "Failed to install the following Android SDK packages as some licences have not been accepted" error Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util This version of Android Studio cannot open this project, please retry with Android Studio 3.4 or newer WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Flutter plugin not installed error;. When running flutter doctor ADB.exe is obsolete and has serious performance problems Android design support library for API 28 (P) not working Flutter command not found How to find the path of Flutter SDK