Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Flutter and app store releases

The resource merge fails because one resource name is declared twice in a source set

Your error

Error: Duplicate resources2 more lines it can show

Fix it fast

Most common cause, 1 of 3

Two files in one res folder share a name but have different extensions

Keep one format per name in each folder.

Fix
git rm app/src/main/res/drawable/logo.png
grep -rn "logo" app/src/main/res app/src/main/java
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Error: Duplicate resources means the Android Gradle plugin found one resource key, such as drawable/logo or string/app_name, twice in one source set while merging. The message prints both paths. Delete or rename one copy: a PNG beside a WebP or XML of the same name, a value defined in two values files, or two overlapping res folders.

  • Applies to Android Gradle plugin 8.x to 9.5.2, Android Studio Rabbit 2 2026.2.2, Gradle 9.9.2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Build from the command line and pull out the lines around the error. Each pair shows the key that clashes and the two files that both declare it; the file types and folders in those two paths tell you which cause applies.

Run this first
./gradlew :app:assembleDebug 2>&1 | grep -B2 -A2 "Duplicate resources"

Then find the line you see in this list and open its fix:

  1. 1Two files in one res folder share a name but have different extensionsBoth paths sit in the same folder and differ only after the dot, for example logo.png and logo.webp
  2. 2The same value is defined in two files of one values folderBoth paths end in values/*.xml and the key is a value type, such as string/, color/ or dimen/
  3. 3res.srcDirs lists two folders that hold the same resourceThe two paths come from different folders that are both listed in sourceSets for the same source set

What does the error look like?

  • Error: Duplicate resources
  • [drawable/logo] /path/to/app/src/main/res/drawable/logo.png [drawable/logo] /path/to/app/src/main/res/drawable/logo.webp: Error: Duplicate resources
  • [string/app_name] /path/to/app/src/main/res/values/strings.xml [string/app_name] /path/to/app/src/main/res/values/extra.xml: Error: Duplicate resources

Cause 1 of 3

Two files in one res folder share a name but have different extensions

You seeBoth paths sit in the same folder and differ only after the dot, for example logo.png and logo.webp

Check

Error: Duplicate resources with two paths in one drawable folder comes from the rule that a resource ID is the file name without its extension. A PNG and a WebP (or an XML vector) with the same base name both become R.drawable.logo, for example when a WebP or vector copy is added and the old bitmap is left next to it.

Check
# print base names that occur more than once in the same res folder
for d in app/src/main/res/*/; do ls "$d" | sed 's/\..*//' | sort | uniq -d | sed "s|^|$d|"; done

Fix

Keep one format per name in each folder. Delete the old file, or rename one of them and update its references.

Fix
git rm app/src/main/res/drawable/logo.png
grep -rn "logo" app/src/main/res app/src/main/java

Verify

Build again. The merge passes and the image still shows in the screens that use it.

Verify
./gradlew :app:assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 3

The same value is defined in two files of one values folder

You seeBoth paths end in values/*.xml and the key is a value type, such as string/, color/ or dimen/

Check

When the bracketed key is a value such as string/app_name and both paths are values XML files in the same source set, the merger saw one item declared twice in one data set. The file names do not matter: strings.xml and a second file such as extra.xml in the same values folder are merged into one pool, so a name may appear only once there.

Check
grep -rn 'name="app_name"' app/src/main/res/values/

Fix

Remove one of the two definitions. If you need a different value for one build, put it in that build type's or flavor's own source set instead, where it overrides main rather than clashing with it.

Fix
<!-- app/src/main/res/values/strings.xml: the only copy in main -->
<string name="app_name">My App</string>

<!-- app/src/debug/res/values/strings.xml: overrides main in debug builds -->
<string name="app_name">My App (debug)</string>

Verify

Build both variants. The merge passes, and the debug build shows its own value.

Verify
./gradlew :app:assembleDebug :app:assembleRelease

Confirmed by android.googlesource.com

Did this fix it?

Cause 3 of 3

res.srcDirs lists two folders that hold the same resource

You seeThe two paths come from different folders that are both listed in sourceSets for the same source set

Check

This duplicate comes from build configuration rather than from a stray file. Gradle gives every directory listed in one source set's res.srcDirs equal priority, so a resource present in two of them cannot be resolved and the merge stops. The same documentation warns against listing a folder together with one of its own subfolders.

Check
grep -n -A6 "sourceSets" app/build.gradle*

Fix

Make each listed folder hold distinct resources, and list either a parent folder or its subfolders, never both. A resource meant to replace another belongs in a higher-priority source set such as a flavor or build type.

Fix
// app/build.gradle.kts
android {
    sourceSets.getByName("main") {
        res.setSrcDirs(listOf("src/main/res", "src/main/res-extra"))  // no overlap between the two
    }
}

Verify

Sync and build. The merge finishes without the duplicate error.

Verify
./gradlew :app:assembleDebug

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • When converting images to WebP, remove the originals in the same commit.
  • Give each values file one topic (strings, colors, dimensions) so a second definition stands out in review.
  • Put per-build values in src/debug or a flavor folder, never as a second copy in main.
  • Keep res.srcDirs lists short and check them for parent and child folders after any project restructure.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: QistLock, Nuclear Home Video.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.