75

I got this strange error with gradle, please help me!

/.../app/build/intermediates/res/debug/drawable-xxhdpi-v4/ic_launcher.png:
    error: Duplicate file
/.../app/build/intermediates/res/debug/drawable-xxhdpi/ic_launcher.png:
    Original is here. The version qualifier may be implied.
Error:Execution failed for task ':app:processDebugResources'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException:
Process 'command '/.../sdk/build-tools/22.0.1/aapt'' finished with non-zero exit value 1

Before it was operating normally, but since I put classpath com.android.tools.build:gradle:1.2.2, this causes me errors

Ivan Bartsov
  • 19,664
  • 7
  • 61
  • 59
Fayçal
  • 1,150
  • 1
  • 12
  • 19

13 Answers13

109

According to Xavier Durochet's explanation on G+, it's due to one of the libraries you use having it's own ic_launcher.png -- which they of course should not (more on that at the bottom).

Chances are the two icons mentioned in the log are different: one is yours and another one is most likely the generic android icon that someone forgot to remove from the library.

To see the offending dependency, hit Ctrl + Shift + N twice (for non-project matching) and type in ic_launcher.png (See the last line on the screenshot) enter image description here

To work around the issue temporarily, add the -v4 qualifier to your drawable resouce folders (or move just ic_launcher.png to *dpi-v4 if you have your reasons) -- credits to Xavier Durochet for the solution. You can also just rename your icon into something else and make corresponding change to AndroidManifest.xml

enter image description here

The real issue is that the offending lib carries the useless icons. Libraries that have their own resources (like ActionBarSherlock or Google's own Support v7 library) use distinctive naming schemes to avoid collisions with your resource names (abs_, abc_).

Launcher icons have no business being in a library so I encourage you to notify the author of the lib you're using that they forgot to remove the redundant ic_launcher.png files.

Also worth mentioning, as Barry Carroll noted very precisely in the same discussion, this doesn't mean your resources should never overlap those in the library: there are a lot of legit reasons to override a lib's resources with your own (e.g. changing the looks of a library-provided activity) and gradle plugin's resource merging logic does allow this, on purpose.

It's just that in this particular case, the conflict occurs when the lib is behind on the android gradle plugin version (pre-1.2.2) in which case resources end up in two different *dpi folders -- with and without the -v4 qualifier; but they're actually in the same resource "bucket" so the system considers them to be duplicate.

This glitch does bring out the useless ic_launcher.png override (actually, a collision -- due to the glitch) but this situation is not universally bad for other kinds of resources.

I.e. sometimes you intentionally override a lib's resource and this glitch will still cause the error message to pop. This time there's no real problem with resource names, so the temporary solution above or holding back the plugin version are the way to go.

Community
  • 1
  • 1
Ivan Bartsov
  • 19,664
  • 7
  • 61
  • 59
  • 2
    Additionally, rebuilding that same library with the latest gradle/build tools will also fix the problem. – danb Apr 30 '15 at 21:55
  • I'm pretty sure my setup is up-to-date though: build tools v 22.0.1, gradle v 1.2.2 – Ivan Bartsov Apr 30 '15 at 21:57
  • UPD oh, rebuilding the *library*, sorry, misread that at first glance :) That would be a suggestion for the library authors in my case. Just curious - any idea on why it fixes the issue? Does the rebuild library have it's drawables in `drawable-*dpi` without the `-v4` suffix? If I understood Xavier right, there's a glitch between `gradle` and `aapt`, `aapt` should put the `-v4` in _our_ app's resources but doesn't -- so we end up with 2 pairs of folders. So, consequently, after `aapt` gets updated, we'll still end up with `-v4` folders and the lib will have to be rebuild again, right? – Ivan Bartsov Apr 30 '15 at 22:07
  • My understanding is that the gradle plugin used to add the -v4 and now it does not. So as long as you're using versions on both sides that either do/don't add the -v4 everything works fine. But it's possible I misunderstood :) in any case, I rebuilt one of our libs with the newest stuff and the problem went away. – danb May 01 '15 at 00:26
  • also make sure that your AndroidManifest.xml does not have a wrong reference to the app icon. Sometimes the ic_launcher.png could be located in mipmap/ rather than drawables/ – JoachimR May 04 '15 at 11:28
  • this should be the accepted answer because it answers the real question behind duplicate file error , thanks for this detailed explanation now i fully understand how to fix something like this in the future. – david Jun 29 '15 at 03:51
  • but is this going to be fixed by gradle / android studio , or the user himself ? – Akshat Aug 19 '15 at 20:13
27

I had the same problem while using a third party library.(RomainPiel/Shimmer-android library on Github)

To solve it, I moved my ic_launcher.png files from drawable folder to mipmap folder. And problem solved.

enter image description here

Can Uludağ
  • 705
  • 8
  • 14
19

Downgrading to com.android.tools.build:gradle:1.1.3 sloved my issue

Fayçal
  • 1,150
  • 1
  • 12
  • 19
14

Here is the general method to find the problem:

Run

./gradlew build --stacktrace --info

and You will find the details of errors. I found my error : a duplicate class caused a TOP-Level error, and remove the duplicated one will solve the problem.

herbertD
  • 10,657
  • 13
  • 50
  • 77
10

For me a simple "clean project" and "rebuild project" did the trick.

Thiago Queiroz
  • 131
  • 1
  • 4
  • This worked for me but using `./gradlew clean` because I was running on Jenkins. Thanks! – epool Jul 27 '17 at 16:46
2

Upgrade to 1.2.3, but ensure that your gradle and buildToolsVersion are identically in your project and the used aars.

In case you use external libs where you can't control the gradle/build version: Contact the author or check the sources by your own. Some libraries have unused launcher icons which will cause this conflict. Removing this icons will solve your problem. Identically named sources (e.g menu.xml) could also cause this issue in rare cases. An easy workaround would be to rename your ressource.

0xPixelfrost
  • 10,244
  • 5
  • 39
  • 58
  • This solved my problem (and also speaks towards Ivan Bartsov's response above in the "worth mentioning" section). A library project (that I imported from Eclipse) had an older "buildToolsVersion" defined in its build.gradle. This caused gradle to fail with the "duplicate file" garbage when building the applications which used that library. After ensuring that the library's "buildToolsVersion" was the same as the application's "buildToolsVersion" gradle stopped "being a damn gradle" and compiled all versions OK. Is there not some lint check or something to give a better error description? – dell116 Jun 15 '15 at 18:11
1

Just rename ic_launcher.png to something else (e.g ico_launcher.png)

Lucy Fair
  • 901
  • 7
  • 9
1

In my case I have added apostrophe s ('s) to strings.xml file. Do check guys for any such error and remove it will definitely help. It's so annoying the IDE can't show the error properly rather makes all resources out of sync..

I know it's not the case which is asked in Question but error is quite same i.e. Gradle execution gets failed.

MobileEvangelist
  • 2,583
  • 1
  • 25
  • 36
1

Simply Rename the Image (Rightclick on the Image, Select Refactor and select Rename). It will solve the issue as the Issue has arise as one of the library is also using the image with the same name.

Pravinsingh Waghela
  • 2,516
  • 4
  • 32
  • 50
1

I had the same problem and what follows worked for me:

  • rename your icon
  • add tools:replace="android:icon" to your <application> tag in the Manifest

You can try just the first step, but I still had problems when merging the manifest files. This way it should override whatever resource was used in the library.

Ayoub
  • 341
  • 1
  • 13
0

Follow this link Here

Or

Make change like this.

repositories {
maven {url "https://clojars.org/repo/"}
}
dependencies {
compile 'frankiesardo:icepick:{{latest-version}}'
**provided** 'frankiesardo:icepick-processor:{{latest-version}}'
}
Roadies
  • 3,309
  • 2
  • 30
  • 46
0

Update to newest gradle plugin 1.5.0 sloved this issue. Update following script in your root build.gradle file

buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
    ...
}
codezjx
  • 9,012
  • 5
  • 47
  • 57
0

I managed to trigger this problem by inconsistent capitalisation of filename extensions. I had a .jpg image in one drawable directory, but an image of the same filename but .JPG in a different drawable directory. The filenames and directories were right, but the extensions weren't.

Peter McLennan
  • 371
  • 4
  • 11