Debugging log · Resources
"Execution failed for task ':app:mergeDebugResources'"
The build stopped at a task called mergeDebugResources, and the headline error is almost useless on its own — it just says the merge failed. But the merge itself is rarely the problem. One resource file in your project is malformed, and the merge is simply the first step that trips over it. The fix is to find that one file.
The short version: Gradle merges every resource from your app and its libraries into one set. If a single file is invalid — a bad name, broken XML, a duplicate, or a corrupt image — the merge halts. Scroll past the headline to the "Caused by" line; it names the actual file and problem.
Read past the headline
The top line (Execution failed for task ':app:mergeDebugResources') is the same no matter the cause. The useful information is underneath, usually after Caused by: or in an > detail line. Run the build with more output if you need it:
./gradlew assembleDebug --stacktrace
Somewhere in there is a path to a specific file under res/ and a reason. That file is your target — everything below is just categories of what that reason tends to be.
Cause 1 — an invalid resource file name
Resource file names are strict: lowercase letters, digits and underscores only, and they must start with a letter. A file like Icon-2.png or menu item.xml — capital letters, hyphens, spaces — breaks the merge. This bites most often when you drop in an asset exported from a design tool with a human-friendly name. Rename it to something like icon_2.png and the merge proceeds.
Cause 2 — malformed XML
A layout, drawable, or values file with a syntax error — an unclosed tag, a stray character, a bad attribute — fails to parse during the merge. If the "Caused by" points at an XML file with a line number, open it there; it's usually a tag that never closed or an attribute missing its quote. Vector drawables are a common offender because their path data is easy to corrupt when hand-edited or pasted.
Cause 3 — a duplicate resource
If two files define the same resource — say colors.xml and another values file both declaring <color name="primary"> — the merge can't decide which wins. The error names the duplicated resource and both locations. Remove or rename one. This also happens across a library and your app; in that case you're overriding intentionally, and the fix is to keep just one definition or use the resource the library expects.
Cause 3b — case-insensitive filesystem clashes
On macOS and Windows the filesystem is case-insensitive, so Background.png and background.png collide as duplicates even though they look distinct. If the error mentions two files that differ only in case, that's the cause — pick one name.
Cause 4 — a corrupt or unsupported image
A truncated PNG, a WebP the build tools can't process, or a "PNG" that's actually a renamed JPEG will fail during resource processing. If the named file is an image, try re-exporting it cleanly from your source, and make sure the extension matches the real format.
Reaching for --stacktrace or the full Gradle console output is the whole game here. The moment you have the file path from "Caused by", the fix is usually obvious — the hard part is realizing the headline task name isn't the thing to debug.
A fast way to narrow it down
- Think about what changed. This error usually appears right after you added or edited a resource — start with that file.
- Clean and rebuild once you've fixed it, so stale merged outputs don't keep reporting the old failure.
- Check
res/for odd names — capitals, hyphens, spaces — if the message is vague; these are the silent, common causes.
File names above are examples — act on the exact path in your own "Caused by" line.