Gradle finished with non-zero exit value 1 (ic_launcher.png: error: Duplicate file)

Android StudioGradleAndroid ResourcesAaptAar

Android Studio Problem Overview


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

Android Studio Solutions


Solution 1 - Android Studio

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.

Solution 2 - Android Studio

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

Solution 3 - Android Studio

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

Solution 4 - Android Studio

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.

Solution 5 - Android Studio

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

Solution 6 - Android Studio

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.

Solution 7 - Android Studio

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

Solution 8 - Android Studio

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.

Solution 9 - Android Studio

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.

Solution 10 - Android Studio

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.

Solution 11 - Android Studio

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}}'
}

Solution 12 - Android Studio

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'
    }
    ...
}

Solution 13 - Android Studio

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.

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
QuestionFay&#231;alView Question on Stackoverflow
Solution 1 - Android StudioIvan BartsovView Answer on Stackoverflow
Solution 2 - Android StudioCan UludağView Answer on Stackoverflow
Solution 3 - Android StudioFayçalView Answer on Stackoverflow
Solution 4 - Android StudioherbertDView Answer on Stackoverflow
Solution 5 - Android StudioThiago QueirozView Answer on Stackoverflow
Solution 6 - Android Studio0xPixelfrostView Answer on Stackoverflow
Solution 7 - Android StudioLucy FairView Answer on Stackoverflow
Solution 8 - Android StudioMobileEvangelistView Answer on Stackoverflow
Solution 9 - Android StudioPravinsingh WaghelaView Answer on Stackoverflow
Solution 10 - Android StudioAyoubView Answer on Stackoverflow
Solution 11 - Android StudioRoadiesView Answer on Stackoverflow
Solution 12 - Android StudiocodezjxView Answer on Stackoverflow
Solution 13 - Android StudioPeter McLennanView Answer on Stackoverflow