Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 973
Daniel Rusev Avatar asked Feb 04 '14 08:02

Daniel Rusev


1 Answers

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

like image 128
muyiou Avatar answered Nov 11 '22 22:11

muyiou