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

后端 未结 13 2352
终归单人心
终归单人心 2020-11-29 18:58

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

/.../app/build/intermediates/res/debug/drawable-xxhdpi-v4/ic_launcher.png:
    error: Duplicate file
/.         


        
相关标签:
13条回答
  • 2020-11-29 19:25

    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}}'
    }
    
    0 讨论(0)
  • 2020-11-29 19:28

    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.

    0 讨论(0)
  • 2020-11-29 19:28

    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.

    0 讨论(0)
  • 2020-11-29 19:36

    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.

    0 讨论(0)
  • 2020-11-29 19:38

    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.

    0 讨论(0)
  • 2020-11-29 19:38

    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'
        }
        ...
    }
    
    0 讨论(0)
提交回复
热议问题