Gradle finished with non-zero exit value 1 (ic_launcher.png: error: Duplicate file)
Solution 1:
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)
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
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:
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.
Solution 3:
Downgrading to com.android.tools.build:gradle:1.1.3 sloved my issue
Solution 4:
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.