Daniel Rusev
Daniel Rusev

Reputation: 1331

Gradle puts duplicate files in the apk file

I'm using gradle 1.10 and the version of the android plugin is 0.8.0. My android projects needs these two jars: jackson-core-asl-1.9.11.jar and jackson-mapper-asl-1.9.11.jar. I add the files thus:

dependencies {
    compile files('libs/jackson-core-asl-1.9.11.jar')
    compile files('libs/jackson-mapper-asl-1.9.11.jar')
}

During gradle build I get an error message saying that these two files are duplicated in META-INF/ASL2.0. I solved the problem by excluding the following files:

packagingOptions {
       exclude 'META-INF/ASL2.0'
       exclude 'META-INF/LICENSE'
       exclude 'META-INF/NOTICE'
       exclude 'META-INF/LICENSE.txt'
       exclude 'META-INF/NOTICE.txt'
       exclude 'META-INF/notice.txt'
       exclude 'META-INF/license.txt'
   }

I have to exclude all of them because there apparently is a duplicate file in all of them.

I'd like to know why this problem occurs. Is it a bug of the android plugin or the gradle itself? Can excluding the above files cause any problems? Am I just excluding the above mentioned jars or is there anything else in those META-INF files? I don't want to exclude anything my project needs

Upvotes: 24

Views: 1439

Answers (2)

muyiou
muyiou

Reputation: 669

First this is not a bug of gradle . It occurs in MergeJavaResourcesTransform task: enter image description here

enter image description here

As we know ,APK is just a zip file, so when put META-INFO/xxx into zip file, if file has been added before ,we can not put it again.

And there is no merge rules for META-INFO files , so we can only add on file which names NOTICE etc

enter image description here

Upvotes: 1

Mick
Mick

Reputation: 188

Here's some info from the Jackson team https://github.com/FasterXML/jackson-databind/issues/214

There are a variety of posts about this on SO, such as this one: Error generating final archive: Found duplicate file for APK: LICENSE.txt

I've used Jackson with Eclipse and Ant as well (and I'm currently using it in Studio with the same workaround you are using), and I had to use zip on the command to rename the license.txt file. There's more info about the whole thing (including an example of using zip to rename the file) in this post Android Gradle plugin 0.7.0: "duplicate files during packaging of APK".

I have not found anything indicating that renaming or excluding these files will have negative consequences, and I never experienced any problems in about 2 years of using Jackson with Eclipse and Ant.

Upvotes: 0

Related Questions